Reputation: 141
I have 2 forms named form1 and form2 in a single php page.form1 contains one text box.form2 contains two text boxes with a submit button.I want to validate all the textboxes when ever submit button pressed.But I cannot access the textbox value in form 1.My code is given below.
<html><body>
<form name=form1 method=POST>
<input type=text name=f1_t1>
</form>
<form name=form2 method=POST>
<input type=text name=f2_t1>
<input type=submit name=sub1>
</form></body></html>
<?php
if(isset($_POST['sub1']))
{
$name=$_POST['f1_t1'];
echo $name;}
?>
this code error as undefined variable f1_t1.Can anyone help please?
Upvotes: 0
Views: 4256
Reputation: 1449
I suggest putting everything in a single form, and displaying/hiding sections of it as necessary (for example, with jQuery and CSS).
As an example, you could do this:
<form>
<div id="part1">
<input name="t1" type="radio" value="v1" />
<input name="t1" type="radio" value="v2" />
</div>
<div id="part2" style="display: none;">
<input name="t2" type="text" />
<input type="submit" />
</div>
</form>
Upvotes: 1
Reputation: 1216
Only the fields in one form are submitted. If for some reason you need to get the falues from a second form, you need to do that before posting, that is, on the client side. You could for example use javaScript to read the value of the field from the first form, write it to a hidden field in the second, and then post that to the server.
Upvotes: 0