Jump to content

Recommended Posts

ive created a form that reloads and displays an error message when one of the fields is left blank like below

 

if($_SESSION['location'] == "")
   {
     $message .= "Please enter a location. ";    
   }

 

but when the page loads back up with the error messages it clears their input, you can click your browsers back button and their input will be there...is there a way that i can make the submit button display the errors but not lose all their input? i have drop-downs and radio buttons in the form as well so i cant just store their input as session variables and redisplay them in the same form..it would lose what they selected in the drop downs and radio buttons....any brilliant ideas? is javascript the answer?

Link to comment
https://forums.phpfreaks.com/topic/141704-form-question/
Share on other sites

ahh u c thats a problem.. you could put the <option> tag's values and html inside an array like

 

$options = array(

  'male' => 'Male',

  'female' => 'Female'

  'other' => 'I\'m A Freak!'

);

 

and then

 

<select name="gender">

<?php

foreach ($options as $value => $text) {

  if ($_REQUEST['gender'] == $value) $selected = " selected='selected'";

  echo '<option value="'.$value.'"'.$selected.'>'.$text.'</option>';

  $selected = '';

}

?>

</select>

Link to comment
https://forums.phpfreaks.com/topic/141704-form-question/#findComment-741856
Share on other sites

It depends. If your processing script is on the same page as the form, then you can use the method used above, as the $_POST data will exist on the same page. But if your processing script is on a different page, then you need to save the data in a cookie, then check for the existence of the cookie when loading the form. If the cookie exists, then load the data into the form.

 

 

Link to comment
https://forums.phpfreaks.com/topic/141704-form-question/#findComment-741962
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.