简体   繁体   中英

Set a radio box as a required entry with the built-in Magento form validation

I have created a few checkboxes that are used on the Magento onepage checkout, I want to use the validation to ensure that the customer selects one of these otherwise the javascript will display the built-in Magento form validation.

<div>
 <li class="control horiz-list">
 <input type="radio" class="radio organisation_type validate-one-required" value="1" id="billing:organisation_type" name="billing[organisation_type]"> <?php echo $this->__('A') ?></li>
 <li class="control horiz-list">
 <input type="radio" class="radio organisation_type validate-one-required" value="2" id="billing:organisation_type" name="billing[organisation_type]"> <?php echo $this->__('B') ?></li>
 <li class="control horiz-list">
 <input type="radio" class="radio organisation_type validate-one-required" value="3" id="billing:organisation_type" name="billing[organisation_type]"> <?php echo $this->__('C') ?></li>
</div>

UPDATE: I now have changed the block of code (as above) - the validation works but I submit the error is displayed at the end of the element rather than the block so the formatting isn't quite right.

Can anyone suggest how I get the error to be correctly displayed at the end of the element?

use validate-one-required-by-name in the class name of the radio button.

or

use validate-one-required on the last radio/checkbox in the group

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM