blt4424 Posted October 12, 2010 Share Posted October 12, 2010 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 More sharing options...
rwwd Posted October 12, 2010 Share Posted October 12, 2010 Methinks that the method should be POST in this instance... GET is when your collecting the data from URL, POST is from form submission (there are exceptions but this isn't it) But I am not convinced that this is a good way of doing this. Rw Link to comment https://forums.phpfreaks.com/topic/215683-form-with-2-handlers/#findComment-1121388 Share on other sites More sharing options...
blt4424 Posted October 12, 2010 Author Share Posted October 12, 2010 I changed to POST, still same problem. Could it be where I close my forms? Link to comment https://forums.phpfreaks.com/topic/215683-form-with-2-handlers/#findComment-1121390 Share on other sites More sharing options...
Faks Posted October 12, 2010 Share Posted October 12, 2010 http://www.jotform.com/ can create java,ajax based forms and with all you want later just download the code edit it and use it as it were your own. Link to comment https://forums.phpfreaks.com/topic/215683-form-with-2-handlers/#findComment-1121406 Share on other sites More sharing options...
blt4424 Posted October 12, 2010 Author Share Posted October 12, 2010 Anyone? Link to comment https://forums.phpfreaks.com/topic/215683-form-with-2-handlers/#findComment-1121485 Share on other sites More sharing options...
AbraCadaver Posted October 12, 2010 Share Posted October 12, 2010 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'] Link to comment https://forums.phpfreaks.com/topic/215683-form-with-2-handlers/#findComment-1121491 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.