View Full Version : How can I split a PHP form into two sections, before submission to a database?

03-19-2010, 04:00 PM
Hi guys,

I have set up a PHP form for a competition, for users to enter and all information to be stored in a database. I used the following NetTut+ tutorial to do so: http://tr.im/SwAd.

I've got the form submitting to the database as required, but with so many additional questions being asked, I would like to split the form into two separate sections. Obviously the first page would say continue to the next step before the second step allowing for the form to be submitted to the database.

The content that the user sees should be split, but should all be a part of the same form. Step 1 > Step 2 before submission.

Would anyone know of or recommend any methods to do this?

I'm a beginner so please be nice. :)



03-19-2010, 04:17 PM

Split it in 2 pages.

Page one <form> sends data to page two.
On page two, put all data into hidden form fields and then post your data to the page where you have your code to insert data into your db.

Edit: sorry, didn't see that you mentionned you are in "beginner mode" ;o) let me explain.

03-19-2010, 04:34 PM
Let's assume that you have 3 php pages.

Page one -> form1.php (first part of your form)
Page two -> form2.php (second part of your form)
Page three -> form_process.php (the page where you process the form data to the database)

Page one (form1.php):

<form action="form2.php" METHOD="post" ENCTYPE="x-www-form-urlencoded">
<input type="text" name="address">

Page two (form2.php):

<form action="form_process.php" METHOD="post" ENCTYPE="x-www-form-urlencoded">
<input type="text" name="more_info">
<input type="hidden" name="address" value="<?=$_POST['address']?>">

Notice that the form ACTION on page one sends to page two. Then ACTION on page two sends to page three, where you process the data (could be the same page...) and the value of your 'address' field (that's just an example) is placed in a hidden field, with the same name and containing the value you passed from page one.

Hope this is clear enough!