Page 1 of 1

help with two form in only one page...

Posted: Tue Feb 18, 2003 6:53 am
by skull cowboy
Hi all,

I need help in order to solve a problem. The problem is:

I have two forms in the same php page, each of this forms contains several text fields and one submit, so my problem consist of I need to obtain the value of a text field associated with the first form from the second form.

my source code is the next:

<form action="control.php" method="post">
<center>
<font color="#FF0000" face="Verdana, Arial, Helvetica, sans-serif" size="12">
<strong>Example 1</strong>
</font>
</center>
<br>


<table width="64%" height="50" border="1" bordercolor="#FFFFFF" bgcolor="#006699">
<tr>
<td width="44%" height="100%"><font color="#FFFFFF">FIELD1</font></td>
<td width="55%">
<input name="field1" type="text">
</td>
</tr>
<tr>
<td width="44%" height="100%"><font color="#FFFFFF">Compuesto</font></td>
<td width="55%">
<textarea name="composicion" rows="10" cols="50" accesskey="" tabindex=""></textarea>
</td>
</tr>

<tr>
<td width="44%" height="100%"><font color="#FFFFFF">Options</font></td>
<td width="55%">
<select name="menu1">
<option value="1" label="option1" disabled selected>Option 1</option>
<option value="2" label="option2" disabled selected>Option 2</option>
<option value="3" label="option3" disabled selected>Option 3</option>
</select>
</td>
<td width="44%">
<input type="submit" name="Aceptar" value="Componer">
</td>
</tr>
</form>
<form action="definicion.htm" method="post" enctype="mimetype" target=" " title="comando totalmente definido">
<tr>
<td width="44%">
<input type="submit" name="Aceptar" value="completado">
</td>
</tr>
</form>
</table>


Could you show me how is possible to do this thing?

thanks in advance.

Posted: Tue Feb 18, 2003 7:00 am
by twigletmac
I'm not entirely sure what you are trying to do - what information do you need to access where?

Mac

Posted: Tue Feb 18, 2003 7:04 am
by skull cowboy
I need obtain the value of the textfield "field1" from the second form.

Posted: Tue Feb 18, 2003 7:05 am
by twigletmac
Sorry, still confused - do you want to access the value posted from form1 in form2 or do you want to somehow set that value by sending it from form2?

Mac

Posted: Tue Feb 18, 2003 7:09 am
by skull cowboy
I Want to access the value posted from form1 in form2 in order to insert this value in a database.

Thanks in advance

Posted: Tue Feb 18, 2003 7:14 am
by twigletmac
Then it's easy - just set it as a hidden field in the second form:

Code: Select all

<form action="definicion.htm" method="post" enctype="mimetype" target=" " title="comando totalmente definido"> 
<input type="hidden" name="field1" value="<?php $_POST['field1']; ?>">
<input type="submit" name="Aceptar" value="completado"> 
</form>
Of course this does depend on the forms being submitted one after the other.

Mac

Posted: Tue Feb 18, 2003 7:18 am
by skull cowboy
it's possible to do the same thing without doing the submit previously?

do you know any other way for doing this?

Thanks

Posted: Tue Feb 18, 2003 7:20 am
by twigletmac
You are going to have to store the variable somewhere, i.e. in a cookie or session, in order to be able to access it later. Why not put the variable into the database when you get it though - if you're not planning on doing anything to it that is.

Mac

Posted: Tue Feb 18, 2003 7:30 am
by skull cowboy
sorry, but this solution is not valid for me. I'll try to explain you more clear the problem. I need to get the value of "field1" wich is contained in the form1, so my problem is that I need to get directly the value of this variable from form2 without doing the submit of form1. How cam i do?

Posted: Tue Feb 18, 2003 7:34 am
by twigletmac
You are trying to get data that hasn't been submitted yet? PHP is server-side so you definitely can't do this with PHP without submitting the page first. Why do you need the variable to go to two different places - it may be that there is a simpler solution to this otherwise you are going to have to find some client-side solution using something like JavaScript.

Mac

Posted: Tue Feb 18, 2003 9:17 am
by skull cowboy
thanks for your help, I thought in JavaScript as solution but i prefered looking for a solution with php.

Your help have been very valious. Thanks.

skullcowboy