我们应该如何将 zend view helper 表单与验证器一起使用 +过滤器?

发布于 2024-09-08 00:12:15 字数 963 浏览 11 评论 0 原文

我们应该如何将 zend view helper 表单与验证器 + 过滤器一起使用?

缺少来自以下验证器和过滤器的示例http ://framework.zend.com/manual/en/zend.view.helpers.html

<form action="action.php" method="post">
 <p>
  <label>Your Email:
   <?php echo $this->formText('email', '[email protected]', array('size' => 32)) ?>
  </label>
 </p>
 <p>
  <label>Your Country:    
   <?php echo $this->formSelect('country', 'us', null, $this->countries) ?>    
  </label>
 </p>
 <p>
  <label>Would you like to opt in?
   <?php echo $this->formCheckbox('opt_in', 'yes', null, array('yes', 'no')) ?>
  </label>
 </p>
</form>

谢谢,

How we should use zend view helper form with validators + filters?

Example that miss validators + filters from: http://framework.zend.com/manual/en/zend.view.helpers.html

<form action="action.php" method="post">
 <p>
  <label>Your Email:
   <?php echo $this->formText('email', '[email protected]', array('size' => 32)) ?>
  </label>
 </p>
 <p>
  <label>Your Country:    
   <?php echo $this->formSelect('country', 'us', null, $this->countries) ?>    
  </label>
 </p>
 <p>
  <label>Would you like to opt in?
   <?php echo $this->formCheckbox('opt_in', 'yes', null, array('yes', 'no')) ?>
  </label>
 </p>
</form>

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羅雙樹 2024-09-15 00:12:15

将表单创建为单独的类,然后您可以使用您想要的所有验证器和过滤器。文档中有完整的设置信息:

http://framework.zend。 com/manual/en/zend.form.quickstart.html

文档示例:

$form = new Zend_Form();
$form->setAction('/user/login')
     ->setMethod('post');

// Create and configure username element:
$username = $form->createElement('text', 'username');
$username->addValidator('alnum')
         ->addValidator('regex', false, array('/^[a-z]+/'))
         ->addValidator('stringLength', false, array(6, 20))
         ->setRequired(true)
         ->addFilter('StringToLower');

// Create and configure password element:
$password = $form->createElement('password', 'password');
$password->addValidator('StringLength', false, array(6))
         ->setRequired(true);

// Add elements to form:
$form->addElement($username)
     ->addElement($password)
     // use addElement() as a factory to create 'Login' button:
     ->addElement('submit', 'login', array('label' => 'Login'));

Create the form as a separate class and then you can use all the validators and filters you wish. There's complete setup info in the docs:

http://framework.zend.com/manual/en/zend.form.quickstart.html

Example from docs:

$form = new Zend_Form();
$form->setAction('/user/login')
     ->setMethod('post');

// Create and configure username element:
$username = $form->createElement('text', 'username');
$username->addValidator('alnum')
         ->addValidator('regex', false, array('/^[a-z]+/'))
         ->addValidator('stringLength', false, array(6, 20))
         ->setRequired(true)
         ->addFilter('StringToLower');

// Create and configure password element:
$password = $form->createElement('password', 'password');
$password->addValidator('StringLength', false, array(6))
         ->setRequired(true);

// Add elements to form:
$form->addElement($username)
     ->addElement($password)
     // use addElement() as a factory to create 'Login' button:
     ->addElement('submit', 'login', array('label' => 'Login'));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文