magento中给form添加输入验证

magento form验证

在magento中添加一个form,可以使用magento本身就有的输入验证功能,今天给大家介绍下如何使用。可以参见我的magento插件教程2中的counter案例

magento中form使用验证

<form action="<?php echo Mage::getUrl('counter') ?>" method="post" id="orderreport-form">
        <fieldset>
            <ul>
                <li>
                    <label for="NUM1"><?php echo $this->__('NUM1: ') ?><span class="required">*</span></label>
                    <input type="text" id="NUM1" name="NUM1" class="input-text required-entry  validate-alphanum" />
                </li>
                <li>
                    <label for="NUM2"><?php echo $this->__('NUM2: ') ?><span class="required">*</span></label>
                    <input type="text" id="NUM2" name="NUM2" class="input-text required-entry validate-alphanum" />
                </li>
                <li>
                    <input type="submit" value="<?php echo $this->__('sub') ?>" />
                </li>
            </ul>
        </fieldset>
</form>
<script type="text/javascript">
//< ![CDATA[
var customForm = new VarienForm('orderreport-form');
//]]>
</script>

观察form的id与input的class,我想你就会用这个magento的验证了,以下为不同验证的报警信息整理。

required-entry  This is a required field.
validate-zero-or-greater Please enter a number 0 or greater in this field.
validate-alphanum Please use only letters (a-z or A-Z) or numbers (0-9) only in this field. No spaces or other characters are allowed.
validate-email Please enter a valid email address. For example johndoe@domain.com.
validate-url Please enter a valid URL. http:// is required
validate-alpha Please use letters only (a-z or A-Z) in this field.

转载表明出处: hellokeykey.com magentokey.com hellokeykey工作室

《magento中给form添加输入验证》有1个想法

评论已关闭。