Jump to content

form question


dadamssg

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

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.