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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Regular Coder
    Join Date
    Jan 2004
    Location
    Des Moines, Iowa
    Posts
    219
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Posting back to same page... <sigh>

    Alright, I have a rather lengthy form that I've decided to split into 7 sections (yup, it is lengthy). I don't want the form on 7 different pages, seems incoherent to me...

    So, I've decided that through the brilliance of PHP I can simply include the whole form on one page, but using if's to echo out the current part of the page...

    The following are the parts of the form that handle whether or not to echo out the current part of the form, I've left out form pieces for space... I guess the main question is... Just how many times can you post back to the same page? it seems to me that after two times... it just kind of pukes and goes bye bye..

    PHP Code:
    //this is form part 1
    <? 
    if (!isset($_POST['pg1']) && !isset($_POST['pg2']) && !isset($_POST['pg3']) && !isset($_POST['pg4']) && !isset($_POST['pg5']) && !isset($_POST['pg6']) && !isset($_POST['pg7'])){ ?>

    //Now the form echos out and I have a hidden variable:
    <form action = "<? echo $_SERVER['PHP_SELF; ?>" name="needsanalysisPg1" method="post">
    <input type="hidden" name="pg1" value="1" />

    //and now we submit
    <? } ?>

    //now we go to form part 2

    <? if (isset($_POST['
    pg1']) && !isset($_POST['pg2']) && !isset($_POST['pg3']) && !isset($_POST['pg4']) && !isset($_POST['pg5']) && !isset($_POST['pg6']) && !isset($_POST['pg7'])){ ?>

    //Now the form echos out and I have a hidden variable:
    <form action = "<? echo $_SERVER['
    PHP_SELF?>" name="needsanalysisPg2" method="post">

    <input type="hidden" name="pg2" value="1" />
    <input type="hidden" name="pg1" value="1" />

    //and now we submit
    <? ?>

    //now we go to form part 3

    <? if (isset($_POST['pg1']) && isset($_POST['pg2']) && !isset($_POST['pg3']) && !isset($_POST['pg4']) && !isset($_POST['pg5']) && !isset($_POST['pg6']) && !isset($_POST['pg7'])){ ?>

    <form action = "<? echo $_SERVER[PHP_SELF?>" name="needsanalysisPg3" method="post">
    and so on and so forth and on it goes until we get to part 7.

    The problem is that once I've submitted part 1, submitting part 2 often(as I've changed and tweaked) goes back to part 1... sometimes it just goes blank... I can never seem to get past two submissions... any help?
    Last edited by rswyatt; 06-08-2004 at 03:43 PM.
    Rich S. Wyatt
    D3 Web Creations

  • #2
    New Coder
    Join Date
    Jun 2004
    Location
    Newcastle, England
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    erm....could you not try having a session....then assigning a session variable with the number ($pageNo or sumthin) which is readable....will this not be an easier way to do it?
    Beauty is in the eye of the beer-holder

    Man who smoke pot, choke on handle

  • #3
    Regular Coder
    Join Date
    Jan 2004
    Location
    Des Moines, Iowa
    Posts
    219
    Thanks
    0
    Thanked 0 Times in 0 Posts
    at the top of the page I do have a
    PHP Code:
    session_start(); 
    So, are you saying that I should:

    <input type="hidden" name="$_SESSION['pg1']" value="1">

    Like that?
    Rich S. Wyatt
    D3 Web Creations

  • #4
    New Coder
    Join Date
    Jun 2004
    Location
    Newcastle, England
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    no. hang on... *looks in trusty php guide*

    k sumthing like this:

    PHP Code:
    session_start();
    session_register(pageNo); 

    Then to read the variable you use something like:

    PHP Code:
     $pageNo $_SESSION[pageNo]; 
    Hope this helps...might do might not!
    Beauty is in the eye of the beer-holder

    Man who smoke pot, choke on handle

  • #5
    Regular Coder
    Join Date
    Jan 2004
    Location
    Des Moines, Iowa
    Posts
    219
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Alright, this part makes sense... I would much rather use a session... the problem is... where am I getting the $pageNo from? I have to have some way that when they click "next" it sets page to 2 then 3 etc

    Quote Originally Posted by MrShed
    no. hang on... *looks in trusty php guide*

    k sumthing like this:

    PHP Code:
    session_start();
    session_register(pageNo); 

    Then to read the variable you use something like:

    PHP Code:
     $pageNo $_SESSION[pageNo]; 
    Hope this helps...might do might not!
    Rich S. Wyatt
    D3 Web Creations

  • #6
    New Coder
    Join Date
    Jun 2004
    Location
    Newcastle, England
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    right erm....hmmm. Have sumthing like....wen it starts the first time(so in your code for the first page u want to display) $pageNo=0.

    Then in some part of the script where it runs each time u load the page have: $pageNo++;

    that should work shouldn't it?


    Actually hang on just thought about that, here it is in a bit more together fashion

    PHP Code:
    if(!isset $_SESSION[pageNo])
    {
    $pageNo 1;
    }
    else
    {
    $pageNo ++;
    }

    session_register(pageNo); 
    Think that'll work....something along those lines anyway. Have it near the top of your code, or in a common bit of code anyways
    Beauty is in the eye of the beer-holder

    Man who smoke pot, choke on handle

  • #7
    New Coder
    Join Date
    Jun 2004
    Location
    Newcastle, England
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    session_start();
    if (!isset(
    $_SESSION[pageNo])
    {
        
    $pageNo 1;
    }
    else
    {
        
    $pageNo $_SESSION[pageNo];
        
    $pageNo++;
    }

    session_register(pageNo);

    //assuming you are using different files for each page
    //if you aren't, just use a switch statement or something

    include 'page'.$pageNo.'php'
    Here is a bit of code I've just written anyways....should work. That's how I would do it anyhow!
    Beauty is in the eye of the beer-holder

    Man who smoke pot, choke on handle

  • #8
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    session_register(pageNo) isn't doing anything. You might wanna change the code to
    PHP Code:
    <?php
    session_start
    ();
    $pageNo $_SESSION['pageNo'];
    if (!isset(
    $pageNo)){ 
        
    $pageNo 1
    }else{ 
        
    $pageNo++; 
    }

    switch (
    $pageNo){
        case 
    1:
        
    // first form here
        
    break;
        
        case 
    2:
        
    // second form here
        
    break;
        
        case 
    3:
        
    // third form here
        
    break;
    }
    ?>
    Probably a better way to do it but as I've not done this for 2 months I can't remember everythin

  • #9
    New Coder
    Join Date
    Jun 2004
    Location
    Newcastle, England
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    youve gotta do the register bit for the variable to be passed with the session variables...havent you??? how does it get passed otherwise?
    Beauty is in the eye of the beer-holder

    Man who smoke pot, choke on handle

  • #10
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Decided to test my code and glad I did. Here's a working version
    PHP Code:
    <?php 
    session_start
    (); 

    if (!isset(
    $_SESSION['pageNo'])){  
        
    $_SESSION['pageNo'] = 1;  
    }else{  
        
    $_SESSION['pageNo']++;
     


    switch (
    $_SESSION['pageNo']){ 
        case 
    1
        
    // first form here
        
    echo 1;
        break; 
         
        case 
    2
        
    // second form here
        
    echo 2;
        break; 
         
        case 
    3
        
    // third form here 
        
    echo '3';
        break; 

    ?>
    You don't need session_register since around version 4.2.0. The super global $_SESSION does all of that now. session_register only works if the register_globals are on, whereas the super global $_SESSION will work if the globals are on or off. http://www.php.net/session-register for more info

  • #11
    New Coder
    Join Date
    Jun 2004
    Location
    Newcastle, England
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    so....if youve got a session, are all the variables used in the session variable??
    Beauty is in the eye of the beer-holder

    Man who smoke pot, choke on handle

  • #12
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Only variables you put into the session variable are entered. In this case it's the number 1 if the session doesn't exist, or the number in the session incremented by 1 if it does exist.

    This line $_SESSION['pageNo'] = 1; is starting the session variable with the value of 1.

  • #13
    New Coder
    Join Date
    Jun 2004
    Location
    Newcastle, England
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oh ok so i take it u mean that now you just bypass the register thing because you just put them in the array directly? Sorry if i seem dumb im very tired!!!!
    Beauty is in the eye of the beer-holder

    Man who smoke pot, choke on handle

  • #14
    Regular Coder
    Join Date
    Jan 2004
    Location
    Des Moines, Iowa
    Posts
    219
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, I've solved part of the problem now... The first part of the form is showing solely... I've coded as per your example... Now, if this makes any diff... I'm posting back to the same page... we're not going to 7 different .php pages, all the same so my form action is
    <? echo $_SERVER['PHP_SELF']; ?>

    So, on submission of part one... it remains in part one.

    I have before the form:
    PHP Code:
    <? switch ($pageNo){ 
            case 
    1?>
    Then the form stuff..

    Then after part one form:
    PHP Code:
    </form>
            <? break; 
            case 
    2:
            
    ?>
    And then part 2 form... and so on... Also, each form is named something different... do my form names have to be the same for all 7 forms?



    Quote Originally Posted by Nightfire
    session_register(pageNo) isn't doing anything. You might wanna change the code to
    PHP Code:
    <?php
    session_start
    ();
    $pageNo $_SESSION['pageNo'];
    if (!isset(
    $pageNo)){ 
        
    $pageNo 1
    }else{ 
        
    $pageNo++; 
    }

    switch (
    $pageNo){
        case 
    1:
        
    // first form here
        
    break;
        
        case 
    2:
        
    // second form here
        
    break;
        
        case 
    3:
        
    // third form here
        
    break;
    }
    ?>
    Probably a better way to do it but as I've not done this for 2 months I can't remember everythin
    Rich S. Wyatt
    D3 Web Creations

  • #15
    New Coder
    Join Date
    Jun 2004
    Location
    Newcastle, England
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is my working test code...ignore the session_destroy bit u wont need that, it was just to make sure it was working. Just use this code directly apart from the session_destroy() and the html bit at the bottom....just put in the stuff in the switch cases that u need to and it shud go!

    PHP Code:
    <?php 
    session_start
    (); 

    if (!isset(
    $_SESSION['pageNo'])){  
        
    $_SESSION['pageNo'] = 1;  
    }else{  
        
    $_SESSION['pageNo']++;  



    switch (
    $_SESSION['pageNo']){ 
        case 
    1
        echo 
    "1";
        break; 
         
        case 
    2
        echo
    "2"
        break; 
         
        case 
    3
        echo 
    "3";
        break; 
        
        default:
        
    session_destroy();

    ?>
    <html>
    <body>
    <form name="form1" method="post" action="test.php">
      <input type="submit" name="Submit" value="Submit">
    </form>
    </body>
    </html>
    Attached Files Attached Files
    Beauty is in the eye of the beer-holder

    Man who smoke pot, choke on handle


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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