Thread: Form handling
View Single Post
Old 11-23-2005, 01:35 PM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,529
sde is on a distinguished road
what redhead said .. and also, the proper format to access that variable is:
Code:
$_GET['Procedures'][0]
for example:
Code:
if ($_GET['Procedures'][0] == 1) {
the problem with your logic is that if they selected treatment 2, then item [0] would equal 2. this means you would have to do a switch or if/else for every single option testing for every possible answer.

you could avoid this by using in_array().

example:
PHP Code:
<?
// create a new variable for the procedures array
if (is_array($_GET['Procedures'])) {
  
$procedures $_GET['Procedures'];
} else {
  
// make new array so our array
  // function below does not break.
  
$procedures = array();
}
?>

<select name="Procedures_two" id="Procedures_two" multiple size="6">

<!-- long way -->
<option value="1" class="form_mult" <?php echo in_array(1$procedures)?" selected":""?>>Acne, Acne Scar & Rosacea Treatment</option>

<!-- shorter way using <?= -->
<
option value="2" class="form_mult" <?=(in_array(2$procedures)?" selected":"")?>>Second type of Treatment</option>

</select>
hope that helps.

:: edited some of the code. if it didn't work the first time, try again ::
sde is offline   Reply With Quote