Multi step form

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
Daz Wilde
Forum Newbie
Posts: 9
Joined: Sun Oct 02, 2005 12:02 pm

Multi step form

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

:D
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

when doing multi-page forms, I store the submissions in session variables so they are easily accessible in the other pages.
User avatar
jwalsh
Forum Contributor
Posts: 202
Joined: Sat Jan 03, 2004 4:55 pm
Location: Cleveland, OH

Post by jwalsh »

Check out the following post, which should give you a head start...

viewtopic.php?t=39316
Daz Wilde
Forum Newbie
Posts: 9
Joined: Sun Oct 02, 2005 12:02 pm

Post 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!
User avatar
dallasx
Forum Contributor
Posts: 106
Joined: Thu Oct 20, 2005 4:55 pm
Location: California

Post 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.
?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

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