最模板 - 外贸网站建设,外贸网站模板

最模板

当前位置: 首页 > Magento > Magento教程 >

magento中给form添加输入验证

时间:2014-07-27 16:58来源:未知 作者:最模板zuimoban 点击:
在magento中添加一个form,可以使用magento本身就有的输入验证功能,今天给大家介绍下如何使用. magento中form使用验证: form action =?php echo Mage::getUrl(********) ? method =post id =test-form ul li label

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

<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和validate-alphanum.
以下为不同验证的报警信息整理:

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.

 

(责任编辑:最模板)
------分隔线----------------------------
栏目列表
推荐内容