Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2009
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Unhappy How can I split a PHP form into two sections, before submission to a database?

    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.

    Cheers,

    Daniel

  • #2
    Regular Coder
    Join Date
    Jan 2008
    Location
    Geneva, Switzerland
    Posts
    413
    Thanks
    12
    Thanked 29 Times in 29 Posts
    Hi,

    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.
    Last edited by Arnaud; 03-19-2010 at 04:25 PM.
    Chuck Norris counted to infinity.
    Twice.

  • #3
    Regular Coder
    Join Date
    Jan 2008
    Location
    Geneva, Switzerland
    Posts
    413
    Thanks
    12
    Thanked 29 Times in 29 Posts
    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):
    PHP Code:
    <form action="form2.php" METHOD="post" ENCTYPE="x-www-form-urlencoded">
    <
    input type="text" name="address">
    </
    form
    Page two (form2.php):
    PHP Code:
    <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']?>">
    </form>
    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!
    Chuck Norris counted to infinity.
    Twice.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •