Jump to content

Form with 2 handlers


blt4424

Recommended Posts

I've searched forever and can't find a solid answer.

 

I'm trying to have a form which then when submitted, is redisplayed with another form under it. Then after submitting the second form, it will redisplay both forms. I almost have this, however I'm running into an unidentified index notice in my two fields from the first form.

 

Here's the inital form.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>User Form 2</title>
</head>

<body>
<?php

?>
<form action = "formhandler2.php" method = "GET">
First name: <input type = "text" name = "fName" /> <br />
Last name: <input type = "text" name = "lName" /> <br />
<input type = "submit" value = "SUBMIT" />
</form>


</body>
</html>

 

And my first formhandler.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Form Handler 2</title>
</head>

<body>

<?php

    function redisplayForm1($inputString)
{
       ?>
<form action = "formhandler2.php" method = "GET">
First name: <input type = "text" name = "fName" value ="<?php echo $_GET['fName'];?>" /> <br />
Last name: <input type = "text" name = "lName" value ="<?php echo $_GET['lName'];?>" /> <br />
<input type="submit" name="submit" value = "SUBMIT" />
</form>
  
<?php
}
echo "This is your completed Part One of the form <br />\n";
echo "<br />\n";
$inputString1 = "";
redisplayForm1($inputString1);
//echo "First Name: ". $_REQUEST['fName']. "<br />";
//echo "Last Name: ".$_REQUEST['lName']. "<br />";

?>
<br />
Please complete Part Two of the form
<form action = "formhandler3.php" method = "GET">
City: <input type = "text" name = "city" /> <br />
State: <input type = "text" name = "state" /> <br />
<input type = "submit" value = "SUBMIT" />
</form>


</body>
</html> 

 

 

And my second handler.php

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Form Handler 3</title>
</head>

<body>

<?php

    function redisplayForm1($inputString1)
{
       ?>
<form action = "formhandler2.php" method = "GET">
First name: <input type = "text" name = "fName" value ="<?php echo $_GET['fName'];?>" /> <br />
Last name: <input type = "text" name = "lName" value ="<?php echo $_GET['lName'];?>" /> <br />
</form>

<br />
Please complete Part Two of the form
<br />


<?php
     }
     function redisplayForm2($inputString2)
     {
         ?>

<form action = "formhandler3.php" method = "GET">
City: <input type = "text" name = "city" value ="<?php echo $_GET['city'];?>" /> <br />
State: <input type = "text" name = "state" value ="<?php echo $_GET['state'];?>" /> <br />
</form>


<?php

     }

echo "This is your completed Part One of the form <br />\n";
echo "<hr />";
echo "<br />\n";

$inputString1 = "";
redisplayForm1($inputString1);


$inputString2 = "";
redisplayForm2($inputString2);
echo "<hr />";

?>
</body>
</html>

 

 

I realize this probably can be done in an easier way, but I'd like to just get a working solution.

 

I appreciate any help!

Link to comment
https://forums.phpfreaks.com/topic/215683-form-with-2-handlers/
Share on other sites

Anyone?

 

If you submit form1 to form2 then form1post/get variables are vailabel in form2, but when you submit form2 to form3 the form1 variables are lost.  You need to add them as hidden inputs to pass them to the next page or add them to the session at each step so that they are available to each page.  I'm confused by your final form as it just submits back to the first or second, but here is an example:

 

form1.php

<form action = "form2.php" method = "GET">
First name: <input type = "text" name = "fName" /> <br />
Last name: <input type = "text" name = "lName" /> <br />
<input type = "submit" value = "SUBMIT" />
</form>

 

form2.php

<form action = "form3.php" method = "GET">
City: <input type = "text" name = "city" /> <br />
State: <input type = "text" name = "state" /> <br />
<input type="hidden" name="fName" value="<?php echo $_GET['fName'];?>">
<input type="hidden" name="lName" value="<?php echo $_GET['lName'];?>">
<input type = "submit" value = "SUBMIT" />
</form>

 

form3.php

<form action = "finish.php" method = "GET">
First name: <input type = "text" name = "fName" value="<?php echo $_GET['fName'];?>"/> <br />
Last name: <input type = "text" name = "lName" value="<?php echo $_GET['lName'];?>"/> <br />
City: <input type = "text" name = "city" value="<?php echo $_GET['city'];?>"/> <br />
State: <input type = "text" name = "state" value="<?php echo $_GET['state'];?>"/> <br />
<input type = "submit" value = "SUBMIT" />
</form>

 

finish.php

// do something with $_GET['fName'] $_GET['lName'] $_GET['city'] $_GET['state']

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.