mercredi 26 août 2015

Checkbox group set variable

HTML code:

 <form id="formular" method="post" action="input.php" enctype="multipart/form-data">
      <div class="input check_boxes required wish_payment_type">
        <div class="wish_payment_type">
        <span class="checkbox payment-radio">
          <label for="wish_payment_type_1">
            <input class="check_boxes required" id="wish_payment_type_1" name="wish[payment_type][]" type="checkbox" value="ridicare produs"><font face ="Impact" size="+3">Vreau s&#259; ridic un produs</font><br /><br />
          </label>
        </span>
        <span class="checkbox payment-radio">
          <label for="wish_payment_type_2">
            <input class="check_boxes required" id="wish_payment_type_2" name="wish[payment_type][]" type="checkbox" value="predare produs"><font face ="Impact" size="+3">Vreau s&#259; predau un produs</font><br /><br />
          </label>
        </span>
    <span class="checkbox payment-radio">
          <label for="wish_payment_type_3">
            <input class="check_boxes required" id="wish_payment_type_3" name="wish[payment_type][]" type="checkbox" value="informatii"><font face ="Impact" size="+3">Vreau s&#259; adresez o &#238;ntrebare</font><br /><br />
          </label>
        </span>
    <span class="checkbox payment-radio">
          <label for="wish_payment_type_4">
            <input class="check_boxes required" id="wish_payment_type_4" name="wish[payment_type][]" type="checkbox" value="reclamatie"><font face ="Impact" size="+3">Vreau s&#259; fac o sesizare</font><br /><br />
          </label>
        </span>
    <span class="checkbox payment-radio">
          <label for="wish_payment_type_5">
            <input class="check_boxes required" id="wish_payment_type_5" name="wish[payment_type][]" type="checkbox" value="factura storno"><font face ="Impact" size="+3">Vreau s&#259; ridic factura storno</font><br /><br /><br /><br />
          </label>
          <input required="required" type="text" class="inp" name="nume" size="30" placeholder="Introdu aici numele &#351;i prenumele t&#259;u"><br /><br /><br /><br />
          <input id='submit' type="submit" onClick="toUpper()" class="buttons" value="&#206;NREGISTRARE"><br /><br />
      </div>
    </form>

Script code:

<script type="text/javascript">
var verifyPaymentType = function () {
  var checkboxes = $('.wish_payment_type .checkbox');
  var inputs = checkboxes.find('input');
  var first = inputs.first()[0];

  inputs.on('change', function () {
    this.setCustomValidity('');
  });

  first.setCustomValidity(checkboxes.find('input:checked').length === 0 ? 'Selectați opțiunea dorită.' : '');
}

$('#submit').click(verifyPaymentType);
</script>

And variable code from input.php:

$motiv = $_POST['wish'];

Maybe I am stupid and cannot see. It returns me ARRAY text, not the values from checkboxes. Anyone has a clear view about setting the right $motiv = $_POST['wish']; please? Cheers :)




Aucun commentaire:

Enregistrer un commentaire