0

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

6
  • Its an array so treat it like one name="interested_in_testing[]" so !empty($_POST['interested_in_testing'][0]).. .. Commented Feb 7, 2014 at 21:47
  • 2
    Add a print_r($_POST); in your code (before the if) and tell us what is displayed please Commented Feb 7, 2014 at 21:47
  • 2
    also <select name="interested_in_testing[ ]" multiple="multiple"> should be <select name="interested_in_testing[]" multiple="multiple"> no space in [] Commented Feb 7, 2014 at 21:48
  • I originally had it without the space. I was trying things :/ @Raphael Malie Since it is an email it doesn't recognize the non html Commented Feb 7, 2014 at 21:50
  • 1
    it's a select. why no use checkboxes if you want multiple values? Commented Feb 7, 2014 at 21:56

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Spaces are allowed within the brackets of a select's name attribute.
I am new to PHP, treating it as an Array was correct in my if statement.

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.