2

I am having a lot of trouble getting a checkbox in a form to then pass to the .php file.. The html looks like

<td><label for="services">Services Requested:</label></td>
<td><form name="services" action="processForm.php" method="post">
          <input type="checkbox" name="services[]" value="Massage" />Massage
          <input type="checkbox" name="services[]" value="Facial" />Facial
          <input type="checkbox" name="services[]" value="Manicure" />Manicure
          <input type="checkbox" name="services[]" value="Pedicure" />Pedicure
          </form>
      </td></tr>

I am setting $services = $_POST['services']; right away in processForm.php. But this error which exists further down in processForm.php still comes up every time.

if(empty($services)) {
$errors[] = "You must choose at least one service.";

}

6
  • Try to do var_dump($_POST) or var_dump($services) to see what you get after submitting the form Commented Mar 2, 2013 at 13:58
  • Where's the submit button? Commented Mar 2, 2013 at 13:58
  • This is just one part of a large form, so the submit button is further down. Commented Mar 2, 2013 at 13:59
  • var_dump($services) returns string(0) "" Commented Mar 2, 2013 at 14:02
  • what about var_dump($_POST)? Commented Mar 2, 2013 at 14:08

2 Answers 2

2

Try change name of checkboxes. They have the same name as form

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

Comments

1

The submit button just represents its form tag, so just to make sure, you didn't do something like this, did you?

<form>
    <!-- HTML Tags -->
    <form name="services" action="form.php" method="post">
        <input type="checkbox" name="services[]" value="Massage" />Massage
        <input type="checkbox" name="services[]" value="Facial" />Facial
        <input type="checkbox" name="services[]" value="Manicure" />Manicure
        <input type="checkbox" name="services[]" value="Pedicure" />Pedicure
    </form>
    <!-- HTML Tags -->
    <input type="submit" value="enviar" />
</form>

If so, you shouldn't do that. Instead, create only one form tag that comprehends all fields!

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.