Home > database >  How to send multi checkbox input value in php reusable forms?
How to send multi checkbox input value in php reusable forms?

Time:11-03

I am using the "reusableforms.com" PHP form script. The form is working well. But I got an error on multi-input checkbox values.

How can I get the multi-input checkbox values?

HTML Code:

<div class="form-box">
    <label>Choose which of the following are most important to you:</label>
    <div class="multi-select">
        <div class="custom-select">
            <input type="checkbox" id="hight-rating" value="High Rating" name="important" hidden>
            <label for="hight-rating">High Rating</label>
        </div>
        <div class="custom-select">
            <input type="checkbox" id="mobile-phone-app" value="Mobile phone app" name="important" hidden>
            <label for="mobile-phone-app">Mobile phone app</label>
        </div>
        <div class="custom-select">
            <input type="checkbox" id="vendor-management" value="Vendor management" name="important" hidden>
            <label for="vendor-management">Vendor management</label>
        </div>
    </div>
</div> 

handler.php

<?php
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);

    require_once './vendor/autoload.php';
    
    use FormGuide\Handlx\FormHandler;    
    
    $pp = new FormHandler(); 
    
    $validator = $pp->getValidator();
    $validator->fields(['name','email', 'phone', 'address', 'property', 'following', 'units', 'date'])->areRequired()->maxLength(50);
    $validator->field('important[]')->maxLength(5000);
    $validator->field('email')->isEmail();
    
    
    $pp->sendEmailTo('[email protected]'); // ← Your email here
    
    echo $pp->process($_POST);
?>

Thank you.

CodePudding user response:

According to your question you are not stating the checkboxes as arrays which you would need to:

<input type="checkbox" id="hight-rating" value="High Rating" name="important[]" hidden>

But if this does not help then it would be useful to elaborate the question a little bit more.

CodePudding user response:

use in html

    <input type="checkbox" id="mobile-phone-app" value="Mobile phone app" name="important[]" hidden>

in php you will receive data in the array so you shout use count not maxLength

$important = $_GET['important'];
$count = count($important);
  • Related