mardi 8 décembre 2015

If statement with && and multiple OR conditions PHP

I'm having trouble trying to make the statement below work the way I want it to.

I am trying to display an error message for an order form if at least one text field is not filled out. Below is a snippet of my PHP code. The 'cookieGiftBox' is the name of a checkbox that users can select and if it is selected, they must enter an amount of cookies under their desired flavors in the text fields provided. How can I display an error message to display when the checkbox IS selected but NO text fields have been filled out?

<?php

if (isset($_POST['cookieGiftBox']) && (!isset($_POST['sugar']) || ($_POST['chocolateChip']) || ($_POST['chocolateChipPecan']) || ($_POST['whiteChocolateRaspberry']) || ($_POST['peanutChocolateChip']) || ($_POST['peanutButter']) || ($_POST['tripleChocolateChip']) || ($_POST['whiteChocolateChip']) || ($_POST['oatmealRaisin']) || ($_POST['cinnamonSpice']) || ($_POST['candyChocolateChip']) || ($_POST['butterscotchToffee']) || ($_POST['snickerdoodle']))) {

    $error.="<br />Please enter an Amount for Cookie Flavors";

}

?>

Aucun commentaire:

Enregistrer un commentaire