multi step form wanted

Discussion in 'PHP' started by clouting, Jan 23, 2008.

  1. #1
    hey folks,

    was wondering if any1 knew some where that i could find out about creating multi step forms (ie.where the form has different pages, the first asking for user details, second contact details etc.....). I have a basic knowledge of PHP, i have found one example but itis overly complex for what i need.

    Does any1 know of any tutorials or anything that might be of help.

    thanks in advance.....
     
    clouting, Jan 23, 2008 IP
  2. webexpert

    webexpert Banned

    Messages:
    188
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try this way;

    upon the post of first page, you can save the data into database, then get the record id. and then you can post that id on other forms placing it on form action query string or can place the id on hidden field or you can create a session that will contain that id.. so the rest of form pages when posted, now it depends on your database structure, if all the fields are in one table, then as i mentioned before, first page post will insert the data into database, and rest of pages will use update query to store the form post data into database table.. and you can do it easily because you have the record id in session or you can manage by placing it in hidden fields..

    if contact us table is different in database... then other form pages will ofcourse use sql insert query to submit the data and will need to insert that id to make the relation logically with other table.. hope it will be helpful..
     
    webexpert, Jan 23, 2008 IP
  3. admins

    admins Peon

    Messages:
    74
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    admins, Jan 23, 2008 IP
  4. redvok

    redvok Active Member

    Messages:
    237
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    58
    #4
    Actually you dont need save data on each step to db, simply place all to session(I dont think you have complex forms with huge data) on each step and retrieve it on last step and then save it in db.
     
    redvok, Jan 23, 2008 IP
  5. webexpert

    webexpert Banned

    Messages:
    188
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i guess he is trying to create a user registration process.. so for each page if he gonna save the values on session.. will really not a good idea.. because someone may take some time to complete his process and in this meanwhile some other user may get register so fast.. so - in this scenario, your suggession is not good enough..

     
    webexpert, Jan 23, 2008 IP
  6. walkere

    walkere Active Member

    Messages:
    112
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #6
    The simplest way to do it would be to take all of the form elements of the first page, put them into new form elements (hidden elements, so the user doesn't see them), and keep passing them along until you get to the final processing page.

    If you do a foreach loop, you can loop through the entire $_POST array and create a new hidden form element for every item in the $_POST array. This snippet should do the trick...

    foreach ($_POST as $name => $value) {
      echo "<input type='hidden' name='$name' value='$value' />";
    }
    Code (markup):
    Good luck,
    - Walkere
     
    walkere, Jan 23, 2008 IP
  7. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #7
    If you save partially-completed forms to a database, you need some way of periodically cleaning out the abandoned entries. Most users will never go all the way through a multi-page form process, so you will end up with a lot of orphan records.
     
    SmallPotatoes, Jan 23, 2008 IP
  8. sharqi

    sharqi Guest

    Messages:
    105
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8

    I agree, this is the simplest way to do it.

    If it was a very long form personally I would just concat the values I want and pass them over as one variable over each time, using a delimter like a * or something then explode the values before i actually use them.
     
    sharqi, Jan 24, 2008 IP
  9. clouting

    clouting Guest

    Messages:
    120
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    hey every1.

    thanks for your replies.
    i will have a go using your advice and see where it gets me.

    thanks.
    clouting
     
    clouting, Jan 24, 2008 IP