Multiple select fields Arrays
Posted: Wed Jul 08, 2009 1:50 pm
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
I have an array which pulls in all form values in as
This works as long as any multiple select fields i.e.
have multiple options selected, but if only one selection is made it returns an empty array for that field.
I'm very new to arrays and I cannot figure out how to get a single selected option to return in the multiple select fields. Any ideas?
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
I have an array which pulls in all form values in as
Code: Select all
foreach ($_POST as $key => $value) {
$value = stripslashes(strip_tags($value));
if (empty($value)) {
exit("<p>Empty fields are not allowed. Please go <a href=\"javascript: history.go(-1)\">Back</a> and fill in the form properly.</p>");
}
//if multiple select count and join option values
if (count($_POST[$key]) >1) {
$_POST[$key] = join(", ", $value);
}
else {$_POST[$key] = stripslashes(strip_tags($value));}
}Code: Select all
<select name="mselect[]" multiple="multiple"><option>Option 1<option>Option 2</select>I'm very new to arrays and I cannot figure out how to get a single selected option to return in the multiple select fields. Any ideas?
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: