Passing multiple variables from a menu

I am trying to get multiple values from the menu “hearabout” to post into a php page. I have searched extensively without any luck. Any help will be appreciated.

<td> <label>Where did you hear about us?(hold Ctrl button to select all that apply)</label></br> <select name="hearabout[]" multiple="multiple"> <option value="internet">Internet</option> <option value="booth">Fair Booth</option> <option value="news">Newspaper/Advertising</option> <option value="word">Word of Mouth</option> <option value="other">Other</option> </select> </td>

[php]<?php

$hearabout = check_input($_POST[‘hearabout’]);
?>

Where did you here about us: <?php echo $hearabout; ?>
<?php function check_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?>[/php]

‘hearabout’ is an array, not a string, this code produces the error:

Warning: trim() expects parameter 1 to be string, array given

You would need to convert the array to a string, for example:

[php]
function check_input($data) {
return implode(", ", $data); // convert array to string
}

$hearabout = array(‘internet’, ‘booth’, ‘word’);
echo check_input($hearabout);

// Output: internet, booth, word
[/php]

I don’t believe you need the trim(), stripslashes(), or htmlspecialchars() functions since these are predefined select values (not user input).

Sponsor our Newsletter | Privacy Policy | Terms of Service