homepage Welcome to WebmasterWorld Guest from 54.225.57.156
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
remember form data after die() ?
CodilX




msg:3608588
 4:10 pm on Mar 23, 2008 (gmt 0)

Hi,

I've noticed this issue in my form. When the script checks for empty fields, if it finds any, it exits using die("empty fields found");. But the problem is that afterwards all the values that where inputed by the user are removed and I get a blank form with the error underneath it.

Is there any way for the form to stay filled after the die()?

Thank you

// form.php:

<html form>
..
if(isset($_GET['submit'])) {

$value1=$_POST['value1'];
$value2=$_POST['value2'];
$value3=$_POST['value3'];

if (empty($value1) empty($value2) empty($value3)) {
die ("Empty fields found"};
} else {
..
rest of php
..
}

 

Scally_Ally




msg:3608608
 4:37 pm on Mar 23, 2008 (gmt 0)

Do you mean when you press back on your browser? does it not remember variables when you refresh the page?

What it should do is re-submit the form when you press refresh. Is this not what happens?

CodilX




msg:3608625
 5:01 pm on Mar 23, 2008 (gmt 0)

It shows the die() bellow the form, and after the die() all the values are deleted. I could post a link for more clarification, but as I understand that's against the rules?

<?
..
echo '<form>..';
if(isset($_GET['submit'])) {
..
if (empty..) {
die("Empty fields found");
}
}

badone




msg:3609021
 9:27 am on Mar 24, 2008 (gmt 0)

Once you use die() your script will lose all it's data unless you use a method of persistence such as serialize()/unserialize(), sessions, or a persistent cache like APC.

Cheers,
badone

CodilX




msg:3609069
 11:33 am on Mar 24, 2008 (gmt 0)

I'm using sessions

henry0




msg:3609105
 1:18 pm on Mar 24, 2008 (gmt 0)

IF you use sessions
then in order to assure that the scripts will not be "confused"
you will just need to start by adding on the first script an "IF" to check if incoming inputs from the landing page are from POST or SESSION
then on the landing page
if isset and !empty $_POST['my_stuff'];
create your my_stuff session

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved