Page 1 of 1

Session fails to return entry to form on error [SOLVED]

Posted: Tue Apr 22, 2008 8:10 am
by eymorais
Having a few issues with the Session capabilities at the moment.

I've got a PHP based form that once submitted goes to a seconday page where the validation and email submittion is completed. I'm trying to add the session capability so that if an error is discovered during the validation, it will re-direct back to the PHP form, indicate the specific error via a case and also re-add the submitter entries so they don't need to re-type the correct information...

On my PHP form page, I do have the session command as the first action within the body.

Code: Select all

 
<?php session_start(); ?>
 
Then on my PHP email handle page, the first php codes are related to my session.

Code: Select all

 
<?php    
 
//************************************************
//PHP Cookie Information                          
session_start();
session_register ("name");
session_register ("email");
session_register ("business");
session_register ("acct");
session_register ("username");
$HTTP_SESSION_VARS ['name'] = $_POST["name"]
$HTTP_SESSION_VARS ['email'] = $_POST["email"]
$HTTP_SESSION_VARS ['business'] = $_POST["business"]
$HTTP_SESSION_VARS ['acct'] = $_POST["acct"]
$HTTP_SESSION_VARS ['username'] = $_POST["username"]
 
Now, for my validation / error redirect it's coded in the following fashion.

Code: Select all

 
if (empty($_POST["name"]) || empty($_POST["email"]) || empty($_POST["business"]))
    {
      // redirect back to form
      header ("Location: ../form.php?error=info");
      exit();
    }
 
The error case does still display after the addition of the session handling, but my original entries are not re-entered automatically within my form text fields. Any ideas?

Re: Session fails to return entry to form on error

Posted: Tue Apr 22, 2008 8:15 am
by andym01480
You'd need to post the form code!
Also var_dump($_SESSION); at the top of the from script, would show us what is happening

Re: Session fails to return entry to form on error

Posted: Tue Apr 22, 2008 8:34 am
by eymorais
On my variable dump I do get my text entries back on my php form....

array(5) { ["name"]=> string(4) "test" ["email"]=> string(4) "test" ["business"]=> string(4) "test" ["csm"]=> string(4) "test" ["username"]=> string(4) "test" }

But they are not dumped to my text boxes... here's a short example of my current form code.

Code: Select all

 
<form name="swift" action="mailer/mail.php" method="post">
<input type="text" name="name" value="" size="35" />
<input type="submit" name="submit" value="Submit" /> 
</form>
 

Re: Session fails to return entry to form on error

Posted: Tue Apr 22, 2008 10:15 am
by eymorais
After doing a bit more searching was able to find what needed to be done.

On the php form, it needs to be setup in this fashion.

Code: Select all

 
<form name="swift" action="mailer/mail.php" method="post">
<input type="text" name="name" value="<? echo $HTTP_SESSION_VARS ['name']; ?>" size="35" />
<input type="submit" name="submit" value="Submit" /> 
</form>
 
REF: http://www.oreilly.com/catalog/webdbapp ... /ch08.html

Re: Session fails to return entry to form on error

Posted: Tue Apr 22, 2008 12:20 pm
by Zoxive
eymorais wrote:After doing a bit more searching was able to find what needed to be done.

On the php form, it needs to be setup in this fashion.

Code: Select all

 
<form name="swift" action="mailer/mail.php" method="post">
<input type="text" name="name" value="<? echo $HTTP_SESSION_VARS ['name']; ?>" size="35" />
<input type="submit" name="submit" value="Submit" /> 
</form>
 
REF: http://www.oreilly.com/catalog/webdbapp ... /ch08.html
$HTTP_SESSION_VARS is the old Session Global Variable.

Use $_SESSION instead.

Re: Session fails to return entry to form on error [SOLVED]

Posted: Wed Apr 23, 2008 8:49 am
by eymorais
Changed my coding and it's still working. Thanks!