0

How to set required field

    <form action="<?php echo $this->getUrl('modulename/index/controlleraction') ?>" id="requestfish">
    <input type="hidden" name="form_key" value="<?php //echo Mage::getSingleton('core/session')->getFormKey(); ?>" />
    <input type="text" name="name" placeholder="Name" required="true" />
    <input type="email" name="email" placeholder="Email" required="true"/>
    <input type="mobile" name="mobile" placeholder="Mobile" required="true"/>
      <?php $addfish = Mage::getStoreConfig('mps_requestfish/enable/addfish');
        $array =  explode(',', $addfish);
        foreach ($array as $item) {
            echo "<div class='list-content'><input class='the-terms' type='checkbox' class='checkbox required-entry' value='$item'><b>$item</b></input></div>";
        }?>
    <textarea name="comment" id="comment" placeholder="Comment"></textarea>

    <input type="submit" value="enter" />

</form>

it add required for all Checkbox. In that if one checkbox i miss it show's error how to over come this?

1 Answer 1

0

Try adding the required-entry class to the input. Then the Magento validation javascript will prevent the form posting without the field.

Also, you are missing a name attribute, so you will not be able to process the response in the form post (although with a required-entry, the answer could only be "yes").

8
  • No it's not working
    – Magento 2
    Commented Nov 30, 2016 at 5:31
  • Is that checkbox inside a form? Magento Validation requires the form to be defined and a form JS created (such as var dataForm = new VarienForm('review-form'); in app/design/frontend/base/default/template/review/form.phtml)
    – Phil M
    Commented Nov 30, 2016 at 16:20
  • it's inside form only
    – Magento 2
    Commented Nov 30, 2016 at 16:25
  • And that form has new VarienForm('something') defined? Also... the validation will only work if the user is submitting the form... they are clicking anywhere else (or a different form) then the checkbox is not going to function as expected... and you might be required to write custom JS to handle the desired behavior.
    – Phil M
    Commented Nov 30, 2016 at 16:28
  • please check my updated question
    – Magento 2
    Commented Nov 30, 2016 at 16:33

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.