mardi 15 septembre 2015

Php checkbox POST array

I have a html contact form that has checkboxes. When I go to get the $_POST data all I see for the checkbox field is ARRAY.

Here is the checkbox snippet form the HTML form

  <div class="col-md-3">
    <div class="checkbox">
      <label>
        <input type="checkbox" name="services[]" value="check 1">Type 1
      </label>
    </div>
  </div>

  <div class="col-md-3">
    <div class="checkbox">
      <label>
        <input type="checkbox" name="services[]" value="check 2 ">Type 2
      </label>
    </div>
  </div>

  <div class="col-md-3">
    <div class="checkbox">
      <label>
        <input type="checkbox" name="services[]" value="check 3">Type 3
      </label>
    </div>
  </div>

  <div class="col-md-3">
    <div class="checkbox">
      <label>
        <input type="checkbox" name="services[]" value="check 4">Type 4
      </label>
    </div>
  </div>

and here is my PHP processing file

$email = $_POST['email'];

if ( is_array ( $_POST['services'] ) ) {
    $services = $_POST['services'];
}

echo 'email is: ' . $email . ' services :' . $services;

Email works fine as its just POST data from one input field. But how do I save the array into a variable so it does something like

$services = "check 1, check 2, check 3";




Aucun commentaire:

Enregistrer un commentaire