效果如下:
magento-form-add-valedate

在magento中添加一个form,可以使用magento本身就有的输入验证功能,今天给大家介绍下如何使用.
magento中form使用验证:

  1. <form action="<?php echo Mage::getUrl('********') ?>" method="post" id="test-form">
  2.  <ul>
  3.    <li>
  4.       <label for="NUM1"><?php echo $this->__('NUM1: ') ?><span class="required">*</span></label>
  5.       <input type="text" id="NUM1" name="NUM1" class="input-text required-entry  validate-alphanum" />
  6.    </li>
  7.    <li>
  8.       <label for="NUM2"><?php echo $this->__('NUM2: ') ?><span class="required">*</span></label>
  9.       <input type="text" id="NUM2" name="NUM2" class="input-text required-entry validate-alphanum" />
  10.    </li>
  11.    <li>
  12.       <input type="submit" value="<?php echo $this->__('sub') ?>" />
  13.    </li>
  14.   </ul>
  15. </form>
  16. <script type="text/javascript">
  17. var testForm = new VarienForm('test-form');
  18. </script>

观察form的id与input的class:
其实最关键的是:required-entry和validate-alphanum.
以下为不同验证的报警信息整理:

  1. required-entry  This is a required field.
  2. validate-zero-or-greater Please enter a number 0 or greater in this field.
  3. 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.
  4. validate-email Please enter a valid email address. For example liuxgnu@qq.com.
  5. validate-url Please enter a valid URL. http:// is required
  6. validate-alpha Please use letters only (a-z or A-Z) in this field.

发表评论

电子邮件地址不会被公开。 必填项已用*标注