Thread: Form handling
View Single Post
Old 11-23-2005, 01:58 PM   #5 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,529
sde is on a distinguished road
maybe you didn't refresh before you got my post? ... i took it a step further since i was playing with it anyway. maybe you already have it setup, but i'd recommend setting up a treatment array since you seem to use this on multiple pages.

here's some code that would make the web app a little easier to work with. keep in mind i don't know the scope of your project and take it with a grain of salt if you are already on a good way to code it.
PHP Code:
<?
// setup a treatment array and call it in an 
// include file since it will be used on multiple pages
$treatments = array(
  
// just make the key (far left number) the same as the value
  // to keep things simple.  you can call a specific treatment by
  // the key then. i.e.: echo $treatments[1]['text']
  
=> array( 'value' => 1'text' => 'Acne, Acne Scar & Rosacea Treatment' ),
  
=> array( 'value' => 2'text' => 'Second Treatment')
  );
  
// make a function to print a single option
// this might also be in an include somewhere
function printOption($value$text$input_array) {
  echo 
'<option value="{$value}" class="form_mult" ' .
    (
in_array($value$input_array)?" selected":"") .
    
'>{$text}</option>\n';
}

// create a new variable for the procedures array
// this code from here down only on this page.
if (is_array($_GET['Procedures'])) {
  
$input_array $_GET['Procedures'];
} else {
  
// make new array so our array
  // function below does not break.
  
$input_array = array();


// now draw your form
?>
<form ..... >
<select name="Procedures_two" id="Procedures_two" multiple size="6"> 
<?
// loop through each treatment and print the option
foreach ( $treatments as $each ) {
  
printOption($each['value'], $each['text'], $input_array);
}
?>
</select>
</form>
:: p.s. edited the heck out of this one too .. fixed ::
sde is offline   Reply With Quote