noobyphpchick
11-07-2007, 04:36 PM
Hi
I have a form which validates on the same page with error messages coming up if information has been inputed incorrectly. The problem is that if radio and dropdown selection has been chosen but an error message comes up for another field the selection the dropdown selection and radio box check does not keep its value. so far i have this
<option value ="$_POST[exercise]"></option>
<option selected></option>
<select name ="exercise">
<select name ="exercise">
<?php
$options = array('',0,2,3,4,5,6,7,;
foreach ($options as $option)
{
echo '<option value="'.$option.'"';
}
if (isset($_POST['exercise'])&&$_POST['exercise']==$option) echo ' selected';
{
echo '>'.$option.'</option>';
}
?>
</select> hours
<font size="2" color="red"><?php print "$exmessage" ?></font><p>
this keeps the selection but only prints the last character in the drop down list - so you can only see number 8.
or
I have this
<option value=" " <?php (isset($_POST[exercise]) && $_POST[exercise] == ' ')? ' selected ':null ?>> </option>
<option value="0" <?php (isset($_POST[exercise]) && $_POST[exercise] == '0')? ' selected ':null ?>>0</option>
<option value="1" <?php (isset($_POST[exercise]) && $_POST[exercise] == '1')? ' selected ':null ?>>1</option>
<option value="2" <?php (isset($_POST[exercise]) && $_POST[exercise] == '2')? ' selected ':null ?>>2</option>
<option value="3" <?php (isset($_POST[exercise]) && $_POST[exercise] == '3')? ' selected ':null ?>>3</option>
<option value="4" <?php (isset($_POST[exercise]) && $_POST[exercise] == '4')? ' selected ':null ?>>4</option>
<option value="5" <?php (isset($_POST[exercise]) && $_POST[exercise] == '5')? ' selected ':null ?>>5</option>
<option value="6" <?php (isset($_POST[exercise]) && $_POST[exercise] == '6')? ' selected ':null ?>>6</option>
<option value="7" <?php (isset($_POST[exercise]) && $_POST[exercise] == '7')? ' selected ':null ?>>7</option>
<option value="8" <?php (isset($_POST[exercise]) && $_POST[exercise] == '8')? ' selected ':null ?>>8</option>
which doesn't keep the selection selected and does not seem to bring up the error message when nothing selected.
does anyone know what im doing wrong? i know its probably a simple-ish problem but i have been stuck for days on this so am really hoping someone will reply many thanks :)
I have a form which validates on the same page with error messages coming up if information has been inputed incorrectly. The problem is that if radio and dropdown selection has been chosen but an error message comes up for another field the selection the dropdown selection and radio box check does not keep its value. so far i have this
<option value ="$_POST[exercise]"></option>
<option selected></option>
<select name ="exercise">
<select name ="exercise">
<?php
$options = array('',0,2,3,4,5,6,7,;
foreach ($options as $option)
{
echo '<option value="'.$option.'"';
}
if (isset($_POST['exercise'])&&$_POST['exercise']==$option) echo ' selected';
{
echo '>'.$option.'</option>';
}
?>
</select> hours
<font size="2" color="red"><?php print "$exmessage" ?></font><p>
this keeps the selection but only prints the last character in the drop down list - so you can only see number 8.
or
I have this
<option value=" " <?php (isset($_POST[exercise]) && $_POST[exercise] == ' ')? ' selected ':null ?>> </option>
<option value="0" <?php (isset($_POST[exercise]) && $_POST[exercise] == '0')? ' selected ':null ?>>0</option>
<option value="1" <?php (isset($_POST[exercise]) && $_POST[exercise] == '1')? ' selected ':null ?>>1</option>
<option value="2" <?php (isset($_POST[exercise]) && $_POST[exercise] == '2')? ' selected ':null ?>>2</option>
<option value="3" <?php (isset($_POST[exercise]) && $_POST[exercise] == '3')? ' selected ':null ?>>3</option>
<option value="4" <?php (isset($_POST[exercise]) && $_POST[exercise] == '4')? ' selected ':null ?>>4</option>
<option value="5" <?php (isset($_POST[exercise]) && $_POST[exercise] == '5')? ' selected ':null ?>>5</option>
<option value="6" <?php (isset($_POST[exercise]) && $_POST[exercise] == '6')? ' selected ':null ?>>6</option>
<option value="7" <?php (isset($_POST[exercise]) && $_POST[exercise] == '7')? ' selected ':null ?>>7</option>
<option value="8" <?php (isset($_POST[exercise]) && $_POST[exercise] == '8')? ' selected ':null ?>>8</option>
which doesn't keep the selection selected and does not seem to bring up the error message when nothing selected.
does anyone know what im doing wrong? i know its probably a simple-ish problem but i have been stuck for days on this so am really hoping someone will reply many thanks :)