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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
eymorais
Forum Newbie
Posts: 14
Joined: Fri Apr 11, 2008 8:38 am
Location: Moncton NB Canada

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

Post 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?
Last edited by eymorais on Tue Apr 22, 2008 10:15 am, edited 1 time in total.
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Re: Session fails to return entry to form on error

Post 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
User avatar
eymorais
Forum Newbie
Posts: 14
Joined: Fri Apr 11, 2008 8:38 am
Location: Moncton NB Canada

Re: Session fails to return entry to form on error

Post 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>
 
User avatar
eymorais
Forum Newbie
Posts: 14
Joined: Fri Apr 11, 2008 8:38 am
Location: Moncton NB Canada

Re: Session fails to return entry to form on error

Post 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
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: Session fails to return entry to form on error

Post 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.
User avatar
eymorais
Forum Newbie
Posts: 14
Joined: Fri Apr 11, 2008 8:38 am
Location: Moncton NB Canada

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

Post by eymorais »

Changed my coding and it's still working. Thanks!
Post Reply