html - PHP form not POSTing multiple select fields

326

My PHP form is not POSTing any of the multiple select options I have in a form. This is my PHP:

if ($_POST['interested_in_testing'] != "")
{
    $_POST['interested_in_testing'] = filter_var($_POST['interested_in_testing'], FILTER_SANITIZE_STRING);
    $interested_in_testing = $_POST['interested_in_testing'];
}
else
    died();

Add to email:

<br/>Interested In Testing: " . $interested_in_testing ;

This is my select:

<label class="custom">Interested In Testing</label>
<select name="interested_in_testing[ ]" multiple="multiple">
  <option value="atas">ATAs</option>
  <option value="ip_phones">IP Phones</option>
  <option value="gateways">Gateways</option>
  <option value="ip_pbx">IP PBX</option>
</select>

It doesn't send anything for this field. All my single fields send fine. Any help? Thank you

916

Answer

Solution:

Since you are creating an array element, you should consider the same as an array on other end as well.

if (is_array($_POST['interested_in_testing']) && !empty($_POST['interested_in_testing'])) {
    $interested_in_testing_val = array();
    foreach($_POST['interested_in_testing'] as $val) {
        $interested_in_testing_val[] = $val;
    }
    $interested_in_testing = implode(',', $interested_in_testing_val);
}

Assumming you want the values as comma separated.

People are also looking for solutions to the problem: php - MediaWiki upgrade (1.19.6 to 1.22.2) breaks - fetchContent() error

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.