Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony sfValidatorSchemaCompare始终返回true_Php_Symfony1 - Fatal编程技术网

Php Symfony sfValidatorSchemaCompare始终返回true

Php Symfony sfValidatorSchemaCompare始终返回true,php,symfony1,Php,Symfony1,以我的形式 <?php class ChangeMyPasswordForm extends sfForm { protected static $labels = array( 'password' => 'Your Password', 'confirm' => 'Re-enter Password', ); public function configure()

以我的形式

<?php

    class ChangeMyPasswordForm extends sfForm {

        protected static $labels = array(
            'password' => 'Your Password',
            'confirm'  => 'Re-enter Password',
        );

        public function configure()
        {   
            $this->setWidgets(array(
                   'password'  => new sfWidgetFormInputPassword(array()),
                 'confirm' => new sfWidgetFormInputPassword(array()),
            ));

            $this->setValidators(array(
                'password' => new sfValidatorPass(),
                 'confirm' => new sfValidatorPass(),
            ));

            $this->validatorSchema->setOption('allow_extra_fields', true); 

            $this->mergePostValidator(
                new sfValidatorSchemaCompare('password', sfValidatorSchemaCompare::EQUAL, 
                    'confirm', array(), array(
                        'invalid'=>'Passwords do not match. Please try again.'
                    )
                )
            );
            $this->widgetSchema->setLabels(self::$labels);   
        }   
    }
在我看来

<?php if ($validated): ?>
<div class="success">
  <b>Success</b>
</div>
<? endif; ?>

<?php if ($form->hasGlobalErrors() || $form->hasErrors()): ?>
<div class="error">
  <b>FAIL !!</b>
  <ul>
    <?php foreach ($form->getGlobalErrors() as $name => $error): ?>
        <li>
            <?php echo $error ?>
        </li>
    <?php endforeach; ?>

    <?php if($form['password']->hasError()): ?>
        <li>
            <?php echo $form['password']->getError() ?>
        </li>
    <?php endif; ?>

  </ul>
</div>
<? endif; ?>

成功
失败!!

我不知道我做错了什么,不管密码是否匹配,表单总是返回成功(除非我将比较改为不相等)。如何判断这些值是否正在返回表单?我有什么明显的错误吗?

您的
bind
呼叫已关闭。它需要一个或两个值,第一个是提交的值,第二个是文件(
$request->getFiles()

让我们关注第一个问题,因为您没有处理任何文件上载

它应该是当前情况下所有表单值的数组,您可以这样做(又称quick-n-DirtyFix):

从长远来看,您应该在
$\u POST
中将表单显示为数组,并将其添加到
配置()

这将使您的输入命名为
changepasswd[password]
changepasswd[confirm]
。绑定变得很容易:

$this->form->bind($request->getParameter($this->form->getName()));

我认为您缺少bind方法中数组的键。它应该类似于$this->form->bind(数组('password'=>$request->getParameter('password'),'confirm'=>$request->getParameter('confirm')),或者更好的是,symfony方式,$this->form->bind($request->getParameter($this->form->getName())。
$this->form->bind(array(
  "password" => $request->getParameter("password"),
  "confirm"  => $request->getParameter("confirm"),
));
$this->widgetSchema->setNameFormat("changepasswd[%s]");
$this->form->bind($request->getParameter($this->form->getName()));