2

Hi I have looked at other answers and they said to add name=checkbox[] to get the array to return but it doesn't appear to working.

The HTML is:

<select class="select" multiple="multiple" name="suburb[]" id="suburb">
<option selected="selected" name="suburb[]" value="Southbank">Southbank</option>
<option selected="selected" name="suburb[]" value="Melbourne">Melbourne</option>
<option selected="selected" name="suburb[]" value="Docklands">Docklands</option>
<option selected="selected" name="suburb[]" value="South Melbourne">South Melbourne</option>
<option selected="selected" name="suburb[]" value="West Melbourne">West Melbourne</option>
<option selected="selected" name="suburb[]" value="Point Cook">Point Cook</option>
<option selected="selected" name="suburb[]" value="Sanctuary Lakes">Sanctuary Lakes</option>
<option selected="selected" name="suburb[]" value="Truganina">Truganina</option>
<option selected="selected" name="suburb[]" value="Williams Landing">Williams Landing</option>

PHP code is:

    $message .= "<tr><td><strong>Interested Suburbs:</strong> </td><td>" . strip_tags($POST_['suburb']) . "</td></tr>";
0

3 Answers 3

3
$_POST['suburb']

Is an array not a string also you mispelled it its $_POST, so you would need to loop through it to post like so:

$message .= "<tr><td><strong>Interested Suburbs:</strong> </td><td>";

foreach ($_POST['suburb'] as $suburb)
{
    $message .= strip_tags($suburb) . "<br />\n";
}

$message .= "</td></tr>";
Sign up to request clarification or add additional context in comments.

Comments

2

Works fine: you just need to use $_POST and print_r the array to see its contents. Try this, and you'll see it works fine.

By the way, you don't need a name attribute on your options

<form method="post" action="<?=$PHP_SELF?>">
    <select name="suburb[]" class="select" multiple="multiple" id="suburb">
        <option selected="selected" value="Southbank">Southbank</option>
        <option selected="selected" value="Melbourne">Melbourne</option>
        <option selected="selected" value="Docklands">Docklands</option>
        <option selected="selected" value="South Melbourne">South Melbourne</option>
        <option selected="selected" value="West Melbourne">West Melbourne</option>
        <option selected="selected" value="Point Cook">Point Cook</option>
        <option selected="selected" value="Sanctuary Lakes">Sanctuary Lakes</option>
        <option selected="selected" value="Truganina">Truganina</option>
        <option selected="selected" value="Williams Landing">Williams Landing</option>
    </select>
    <button type="submit">test</button>
</form>
<?php
print_r($_POST['suburb']);
?>

1 Comment

PS - temporarily, you can see this in action at stevenmoseley.com/test.php - where I tested it
1

The variable you're looking for is $_POST, not $POST_; see the PHP reference on $_POST for more details.

Otherwise, from what you have shown, it's probably fine. Add the HTML for your form tag as well if things still don't work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.