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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2003
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Redirect without losing information

    How to Redirect a page to the other page with the values in the text fields retained. i.e, Page 1 gets the information from the user, validates the information in the page 2 and it needs to redirect again to page 1, if the informations are not valid. Thnx. Bye

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    easiest way is to do everything on page 1.. i.e. page1.htm has a form action of page1.htm , page1 itself decides if it is supposed to be processing or showing the form.

    PHP Code:
    <?
    if($_POST['submit']){
    //process form//

    //if process success 
     
    if(!$errors){
        
    header('location:thanks.page');
        exit();
      }
    }

    //still here ? - show the form
    ?>
    <form action="page1.htm"..
    ...
    <input type="text" name="field" value="<?=$_POST['field'];?>">
    etc

    another way is to store all $_POST & $_GET data in a session which you can pass from page to page really easily.

    so on page2.htm , process the form, if there are errors you can add the form data to a session & send back to page1 (or indeed anywhere else..

    PHP Code:
    <?
    session_start
    ();
    if(
    $_POST['submit']){
     
    //process form
      //error occurs ?
      
    $_SESSION['post_data']=$_POST;
      
    header('location: page1.htm');
    }
    ?>

    page1.htm ... if the post_data exists we can use it.

    <?
    session_start
    ();
    if(
    $_SESSION['post_data']){
      
    $_POST=$_SESSION['post_data'];
    }
    ?>
    etc
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

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