www.webdeveloper.com
Results 1 to 5 of 5

Thread: Form Processing

  1. #1
    Join Date
    May 2010
    Posts
    35

    Form Processing

    What is the best way to process a form when you want to display the results on a different page & keep the session variables?

    I have a form that I'm trying to process and if the user does not enter required information in certain fields they are kept at the same page with the error displayed about which required fields they need to fill out before they can proceed.

    So, I'm trying to post the info from edit.php to results.php. My form action on edit.php is edit.php & then I'm using header() in an if/then statement if all variables are filled out.

    But when I try to redirect with header() my session variables don't convert, nor does the $_POST variables convert.

    Is there a better way to do this without having to query the database to restore all my variables or is this the best way to process the form?

  2. #2
    Join Date
    May 2010
    Posts
    123
    by 'variables' I assume you mean the form fields that the user needs to fill out?

    So, I'm trying to post the info from edit.php to results.php. My form action on edit.php is edit.php
    shouldnt the form action be results.php if you are going from edit.php?

    The way I usually do this is check that all of the fields have been passed over to results.php with code in results.php.

    So in the results.php have:

    PHP Code:
    if( isset($_POST['test']) ){
    //do what you wanna do
    }else{
    header('location:test.php');


  3. #3
    Join Date
    May 2010
    Posts
    35
    I have action set to the same page for a user error loop, such as you didn't not fill out username.

    Then, if they successfully enter all the required fields, I will send them to results, via header(location:results.php). But, when header is called, it doesn't have any of the $_POST nor $_SESSION variables.

    So, how do I get my variables back into the session? Or should I handle my user error messaging differently?

  4. #4
    Join Date
    Mar 2010
    Posts
    2,803
    submitting a php page to itself is fine but without seeing your code, it's hard to tell exactly why your session vars. are not seen in results.php

    But the first obvious thing to check is that you have

    Code:
     
    session_start();
    at the top of edit.php and results.php

    If you have, and if pain persists , then maybe post the code in both php files so we can see what is going on.
    Last edited by tirna; 05-30-2010 at 06:26 PM.

  5. #5
    Join Date
    May 2010
    Posts
    35
    Quote Originally Posted by tirna View Post
    submitting a php page to itself is fine but without seeing your code, it's hard to tell exactly why your session vars. are not seen in results.php

    But the first obvious thing to check is that you have

    Code:
     
    session_start();
    at the top of edit.php and results.php

    If you have, and if pain persists , then maybe post the code in both php files so we can see what is going on.
    Ok. It looks like I wasn't passing any variables with the header () function nor was I using $_GET.

    For example:

    test.php having

    PHP Code:
    header("location:result.php?var1=$var1&var2=$var2"); 
    then result.php having

    PHP Code:
    $var1 $_GET['var1'];
    $var2 $_GET['var2']; 
    Then I can query the DB for the rest of my variables.

    I hope this helps someone else with form processing.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles