Jump to content

Browser back button loses user input


PaulM9

Recommended Posts

Hello Everyone,

Looking for some help with a form losing user input when clicking the browser back button.

I have the code working perfectly when people register (ie if they forget to complete a field, they are kicked back to the form, and their other input is still there), however once a user logs into the site and wants to create a MySQL record using another form, if they leave a field empty and they get kicked back to fill in the blank field, all their other  inputs are gone and they have to start filling the entire form again. I use the same logic for both, but one does not work.

 

Any clues as to what could be wrong in the second scenario?

 

 

if ($action=="add")

{

$dberror = "";

 

//add slashes to input so things don't get messed up in mySQL

$city = addslashes($city);

 

// check for blank fields

 

if ($title == "")

{die ("<P>Please select a title!<P><FORM><INPUT TYPE=\"BUTTON\" VALUE=\"BACK\" onClick=\"history.back()\"></FORM>");}

elseif ($city == "")

{die ("<P>Please enter your city / town!<P><FORM><INPUT TYPE=\"BUTTON\" VALUE=\"BACK\" onClick=\"history.back()\"></FORM>");}

elseif ($state == "")

{die ("<P>Please select your country!<P><FORM><INPUT TYPE=\"BUTTON\" VALUE=\"BACK\" onClick=\"history.back()\"></FORM>");}

 

else

//success! Go ahead and enter the record

 

Then the record gets added to the MySQL database fine, no issues here.

Further down the code is the input section, and I use this method:

 

print "<form name=\"addlisting\" action=\"./agentadmin.php?action=add\" method=post>";

….code for date entry here – standard stuff.

print "<input type=submit value=\"Submit\"></form>";

 

 

 

 

Thank you,

Paul.

 

Link to comment
https://forums.phpfreaks.com/topic/250511-browser-back-button-loses-user-input/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.