Page 1 of 1
Multi step form
Posted: Fri Oct 21, 2005 9:42 am
by Daz Wilde
Has anyone got or done a multi step form or a multi page form.
I would like it also if users could go back and edit anything they've filled in.
I want about 3 or 4 pages with various questions on.
Thanks in advance!!!

Posted: Fri Oct 21, 2005 9:46 am
by foobar
Just have one form post to the next one, etc. If you want the back & forth to work, you'll have to put all the form data into a var on the receiving end, and put it into the Back and Forward links, respectively.
Posted: Fri Oct 21, 2005 9:58 am
by feyd
when doing multi-page forms, I store the submissions in session variables so they are easily accessible in the other pages.
Posted: Fri Oct 21, 2005 10:50 am
by jwalsh
Check out the following post, which should give you a head start...
viewtopic.php?t=39316
Posted: Sat Oct 22, 2005 12:59 pm
by Daz Wilde
foobar wrote:Just have one form post to the next one, etc. If you want the back & forth to work, you'll have to put all the form data into a var on the receiving end, and put it into the Back and Forward links, respectively.
Im a bit of a newbie so can you just explain how to send the form to the next.
Ive only set up forms which just get submitted to mail.
Sorry for being a pain like!
Posted: Sat Oct 22, 2005 1:29 pm
by dallasx
Although sessions are alot easier, here's is the way without using them. If they go back they'll lose the information though.
Your form page: myform.html
Code: Select all
<form name="form1" method="post" action="page1.php">
<p>Enter your name:<br>
<input type="text" name="users_name">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
Your next page (aka the action page): page1.php (notice the action value in myform.html)
Code: Select all
<?php
$name = $_POST['users_name']; //the value of the POST must be the same name as the form field value.
echo $name;
// ECHO OUT MORE FORM STUFF
//but if you want to carry variables from page to page, you could do it like this.
//For ever form value you capture on any page, you need to have the same number of hidden fields at the end of the form.
//the hidden field value needs to echoed out to the value in order for the form to take the value with it.
echo "<input type=\"hidden\" name=\"users_name\" value=\"". $name ."\">";
//on the next you would repeat something like the $_POST['users_name'] above.
?>
Posted: Sat Oct 22, 2005 5:04 pm
by John Cartwright
mentioned by page, assign each page a value (page number) and store these results in a session array.
Example
http://domain.com/form.php?page=1
Code: Select all
$page = (!empty($_GET['page']) ? (int)$_GET['page'] : 1);
if (isset($_POST['submit'])) {
$_SESSION[$page] = $_POST;
header('Location: http://domain.com/form.php?page='.($page + 1));
exit();
}
Now this is still flawed, but it gives you an idea of what is involved,