help with two form in only one page...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
skull cowboy
Forum Newbie
Posts: 14
Joined: Tue Jan 21, 2003 3:04 am

help with two form in only one page...

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

I'm not entirely sure what you are trying to do - what information do you need to access where?

Mac
skull cowboy
Forum Newbie
Posts: 14
Joined: Tue Jan 21, 2003 3:04 am

Post by skull cowboy »

I need obtain the value of the textfield "field1" from the second form.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
skull cowboy
Forum Newbie
Posts: 14
Joined: Tue Jan 21, 2003 3:04 am

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
skull cowboy
Forum Newbie
Posts: 14
Joined: Tue Jan 21, 2003 3:04 am

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
skull cowboy
Forum Newbie
Posts: 14
Joined: Tue Jan 21, 2003 3:04 am

Post 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?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
skull cowboy
Forum Newbie
Posts: 14
Joined: Tue Jan 21, 2003 3:04 am

Post 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
Post Reply