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 14 of 14
  1. #1
    Regular Coder
    Join Date
    May 2004
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    php form question

    hi all,

    I have a form using php. There are about 30 input fields. instead of having 1 page with a long form, i wanted to break it down into say 3 pages with 10 fields each using say a "next" link or button.

    the field values in the first page wont pass to the next, even though i am not closing the form until all pages are complete. I'm not sure if this is possible but would like any ideas on how to do it.

    tnx,
    c.c.

  • #2
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    look up sessions
    http://uk2.php.net/manual/en/ref.session.php
    store a variable in the session like so
    PHP Code:
    session_start();
    $_SESSION['field1'] = $_POST['field1'];
    echo 
    '<form..........>'
    but you have to have session_start(); at the top of every page
    which has the form on
    Last edited by rafiki; 03-29-2007 at 12:40 AM.

  • #3
    Registered User
    Join Date
    Apr 2006
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Something else you could do is have different sections of the form on one page and let it do one part at a time. Then at the end you could do the MySQL insert part.

  • #4
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Quote Originally Posted by sirborder View Post
    Something else you could do is have different sections of the form on one page and let it do one part at a time. Then at the end you could do the MySQL insert part.
    sessions would be easier if you wanted to add all the fields into the same table
    if you wanted one table for different parts of the form group them together in form and do it as sirborder said

  • #5
    Regular Coder
    Join Date
    May 2004
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for the replies

    I never thought to use $_SESSIONS to do the task. DOH!

    tnx again,
    c.c.

  • #6
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    You could use hidden fields with the info from the the other pages dynamically put into the hidden fields!

    Mabie?

  • #7
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    That would be an unstable and unreliable solution.

  • #8
    Regular Coder
    Join Date
    May 2004
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have used:
    PHP Code:
    session_name();
    session_start(); 
    at the beginning of the page.
    i can echo a session variable after the first submit, yet I keep creating a new session every time the page refreshes.

    for each "page" of the multiple page form, i am using <submit> and afterward placing the form vars in a session. and echoing the next form.
    Last edited by ClubCosmic; 03-30-2007 at 10:38 PM.

  • #9
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Code:
    session_name();
    You don't need this.

  • #10
    Regular Coder
    Join Date
    May 2004
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i removed it. it still creates a new session. originally i didnt have session_name but tried it after reading around.

    i have used session before without this happening.

  • #11
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    I can't think of anything that could cause this, except that perhaps you are blocking the cookie that is required for this to work.

  • #12
    Regular Coder
    Join Date
    May 2004
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i did figure this much out. if i link to another page before submitting the form on page 1, then it keeps the same session.

    problem is,
    i am using a switch statement to choose a function which is all on the same same so it keep making a new session every time the page refreshes.

    should i refresh the page before session_start() ?

  • #13
    Regular Coder
    Join Date
    May 2004
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the problem was the usually suspect.....ME!

    i was using an if(isset($_POST[submit])) statement to determine whether or not to run the switch() statement.

    not sure how this would cause that to happen but its working

    thanks for the replies!!!

  • #14
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    I also find that my own stupidity is the root of all my problems


  •  

    Posting Permissions

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