Hi!
Maybee your form look like this:
<form action="" method="post">
<select name="pid[]" multiple>
<option value="name1">Name 1</option>
<option value="name2">Name 2</option>
...
...
</select>
<input type="submit" value="SUBMIT">
</form>
This is just examples on ways to access and manipulate the select element:
// Take a look at the $_POST array when you are testing.
echo '<pre>';
print_r($_POST);
echo '</pre>';
if(!isset($_POST['pid'])) {
$error = 'You have to select some stuff.....';
}
else {
// Count selected.
$numbSelected = sizeof($_POST['pid']);
$minimumSelected = 2;// or 3 or 5 or 20.
if($numbSelected < $minimumSelected) {
$error = 'You have to select minimum '.$minimumSelected.' names.';
}
$allNames = array_values($_POST['pid']);
if(!in_array('name1', $allNames)) {
$error = 'You have to select Name 1....';
}
else if(!in_array('name2', $allNames)) {
$error = 'You have to select Name 2....';
}
$namePattern = '/^[a-z-A-Z \.]+$/';
$error = '';
forach($allNames as $value) {
if(!preg_match($namePattern, $value)) {
$error.= '...';
}
}
}
I hope this would give you some help.