Welcome to WebmasterWorld Guest from 54.162.232.51

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

remember form data after die() ?

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

Junior Member

10+ Year Member

joined:June 10, 2007
posts: 104
votes: 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
..
}

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

Full Member

10+ Year Member

joined:Aug 3, 2005
posts:269
votes: 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?

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

Junior Member

10+ Year Member

joined:June 10, 2007
posts:104
votes: 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");
}
}

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

Junior Member

10+ Year Member

joined:Jan 27, 2005
posts:181
votes: 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

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

Junior Member

10+ Year Member

joined:June 10, 2007
posts:104
votes: 0


I'm using sessions
1:18 pm on Mar 24, 2008 (gmt 0)

Senior Member from FR 

WebmasterWorld Senior Member henry0 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 19, 2003
posts: 4408
votes: 5


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
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members