简体   繁体   English

使用内置的Magento表单验证将单选框设置为必填项

[英]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. 我已经创建了一些用于Magento单页结帐的复选框,我想使用验证来确保客户选择其中之一,否则javascript将显示内置的Magento表单验证。

<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. 在单选按钮的类名称中使用需要validate-one-required-by-name名称。

or 要么

use validate-one-required on the last radio/checkbox in the group 在组中的最后一个单选/复选框上使用需要validate-one-required

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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