【问题标题】:How can I add multiple validatiors on a field in symfony 1.4如何在 symfony 1.4 中的字段上添加多个验证器
【发布时间】:2011-06-15 06:54:30
【问题描述】:

我已在位于
{app}/lib/form/doctrine/base

我正在尝试将两个验证器添加到 EMAIL 字段的“BaseUserForm”类中编写此代码。

$this->setValidators(array(
        'id' => new sfValidatorChoice(array(
            'choices' => array(
                $this->getObject()->get('id')
            ),
            'empty_value' => $this->getObject()->get('id'),
            'required' => false
        )),
        'name' => new sfValidatorString(array('max_length' => 50)),
        'email' => array(
            new sfValidatorString(array('max_length' => 100)),
            new sfValidatorEmail(array('trim' => true))
        ),
        'password' => new sfValidatorString(array('max_length' => 100)),
        'retyepassword' => new sfValidatorString(array('max_length' => 100)),
        'city_id' => new sfValidatorDoctrineChoice(array(
            'model' => $this->getRelatedModelName('Cities')
        )),
        'phone' => new sfValidatorNumber(),
        'created' => new sfValidatorDateTime(),
        'updated' => new sfValidatorDateTime(),
    ));

上面的代码在为电子邮件字段定义两个验证器时出错。

此外,我发现很难找到这些验证器的相关代码(示例显示用法)。 jobeet 教程没有太大帮助。

请分享一些不错的博客/文章/论坛,我可以在其中找到与上述问题相关的帮助。

谢谢

【问题讨论】:

    标签: forms symfony-1.4 field validation


    【解决方案1】:

    sfValidatorAnd() 会有所帮助;

    祝你好运

    【讨论】:

      【解决方案2】:
      'email'       => new sfValidatorEmail(array('max_length' => 25, 'required' => TRUE),
                                                    array('invalid' => 'The email address is invalid.', 'required' => 'Email Id is required.', 'max_length'=> 'Maximum 25 characters allowed.')),                                
      

      【讨论】:

        猜你喜欢
        • 2012-04-28
        • 1970-01-01
        • 1970-01-01
        • 2011-09-23
        • 1970-01-01
        • 2011-09-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多