在magento中添加一个form,可以使用magento本身就有的输入验证功能,今天给大家介绍下如何使用. <form action="<?php echo Mage::getUrl('********') ?>" method="post" id="test-form"> <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> </form> <script type="text/javascript"> var testForm = new VarienForm('test-form'); </script>
观察form的id与input的class: 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 liuxgnu@qq.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. (责任编辑:最模板) |