this is my form :
$html = "";
$html .= "<div id='options'>";
$html .= "<form action='filter.php' method='get'>";
$html .= "<select multiple='multiple' name='options'>";
foreach($selectValues as $option){
$html .= "<option value='$option'>$option</option>";
}
$html .= "</select><input type='submit' value='submit'></form></div>";
but if i do not select an option from the box and i submit i get the error “Undefined index: options ” i want to be able to submit and have it pass a defualt value if nothing is selected
You should probably fix your code in the backend instead to do a
!empty($_GET['options'])check. Secondly, your field name should beoptions[], notoptions, as it will get overwritten with the last selected value (due to the way PHP handles input). Thirdly, you might want tohtmlspecialchars()your$optionwhen you output it. This ensures that weird options won’t break your HTML. Finally, if your option has the same value as its label, you don’t need to specify it as the value as well.