Jump to content

Recommended Posts

It's common courtesy to ensure that a form with validation problems reposts with the fields still filled in, so the user doesn't have to start over, by echoing the variables in the Value attribute of the text fields, but I also want to have a drop-down menu to be sticky and retain its selected state when the page reposts.

It's basically a static dropdown on a registration page, it then posts, validates, if errors are detected, i need the person to fix the problems, but the drop-down boxes lose their values. I need to retain this.

$options = array ('One', 'Two', 'Three', 'Four');

echo "<select name=\"number\">\n";
foreach ($options as $optValue)
{
    $selected = ($optValue == $_POST['number']) ? ' selected="selected"' : '';
    echo "<option value=\"{$optValue}\"{$selected}>{$optValue}</option>\n";

}
echo "</select>\n";

 

EDIT: Corrected a couple errors

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.