Hi,
I don't even know how to properly descrbe this. but here goes.
I have a page with a form on it including multiple selection capable lists. Theses lists values are being pulled from an sql database. Once submitted the page will self process and continue if error free yada yada yada... But if not we are back at square one..
how do i get the selected values from the list to stay when the page reloads when there was an entry error?
In text fields I just <?php echo $_POST['value']; ?> in the value attribute.
Thanks a million,
Lists To Maintain Values On Self Processing Page
Moderator: General Moderators
-
Subliminal
- Forum Commoner
- Posts: 40
- Joined: Thu Oct 23, 2003 8:12 pm
The problem is browser dependant. Some keep the value of the initial selection even though you might assign a new value with the selected statement. You can also set the cache-control on the form site but it does not entirely fix the problem.
I normally use a verification page and don't use php-self for the call. In this case you can simply display the correct option by using selected.
I normally use a verification page and don't use php-self for the call. In this case you can simply display the correct option by using selected.
-
Subliminal
- Forum Commoner
- Posts: 40
- Joined: Thu Oct 23, 2003 8:12 pm
Thanks guys.. I am just a little confused as to how though? For every menu item I put an if statement to search the array for that value? similar to the field example?
This is the code I use currently... works maybe there is a better way to do it and have what i am trying to do integrate a bit better?
THANKS
This is the code I use currently... works maybe there is a better way to do it and have what i am trying to do integrate a bit better?
Code: Select all
<select name="menu[]" size="7" multiple id="menu">
<?php
// Get Menu Values From Database
$menu_query = mysql_query("SELECT * FROM menus WHERE menu='MENUa'");
while ($row = mysql_fetch_array($menu_query))
{
echo "<option value='{$row["value"]}'>{$row["item"]}</option>\n";
}
?>
</select>i think code would look like:
Code: Select all
echo "<select name='{$column['name']}'>";
foreach($column['options'] as $option)
{
$selected = '';
if (in_array($option['value'] == $POST[$column['name']]))
{
$selected = ' selected';
}
echo "<option value={$option['value']}{$selected}>{$option['name']}</option>";
}
echo "</select>";