Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.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
Symfony1 Symfony 1.4中的验证表_Symfony1_Symfony 1.4 - Fatal编程技术网

Symfony1 Symfony 1.4中的验证表

Symfony1 Symfony 1.4中的验证表,symfony1,symfony-1.4,Symfony1,Symfony 1.4,我在项目中创建了一个搜索表单,但验证似乎不起作用: 过滤器搜索格式: class FilterSearchForm extends sfForm { public function configure() { $def_volume = array(-1=>"Please select a volume"); $def_issue = array(-1=>"Please select issue"); $volumes = array_merge($def_volu

我在项目中创建了一个搜索表单,但验证似乎不起作用:

过滤器搜索格式:

class FilterSearchForm extends sfForm
 {
  public function configure()
    {

$def_volume = array(-1=>"Please select a volume");
$def_issue = array(-1=>"Please select issue");

$volumes = array_merge($def_volume,IssuePeer::getAllVolumesForListChoices());
$issues = array_merge($def_issue,IssuePeer::getAllIssuesForListChoices());


//******************************** WIDGET **************************************//
   $this->setWidgets(array(
  'keyword'    => new sfWidgetFormInput(),
  'volume' => new sfWidgetFormSelect(array('choices' => $volumes)),
  'issue' => new sfWidgetFormSelect(array('choices' => $issues)),
));

           //*****************************************  VALIDATORS           
          **********************************//
   $this->setValidators(array(
  'keyword'    => new sfValidatorString(array('required' => true)),
  'volume' => new sfValidatorChoice(array('choices' => array_keys(IssuePeer::getAllVolumesForListChoices()))),
  'issue' => new sfValidatorChoice(array('choices' => array_keys(IssuePeer::getAllIssuesForListChoices()))),
));


$this->widgetSchema->setNameFormat('filterSearch[%s]');
$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

}
}

在搜索操作中:

$this->form = new FilterSearchForm();
在搜索模板中:

            <form id="form_content" method="post" action="<?php echo url_for('@ResultSearch')  ?>">
                <?php echo $form->renderHiddenFields(); ?>

            <?php if($form->hasGlobalErrors()): ?>
            <ul class="error_list">
                <?php foreach($form->getGlobalErrors() as $name => $error): ?>
                <li><?php echo $error; ?></li>
                <?php endforeach; ?>
            </ul>
           <?php endif; ?>
                <div class="search_word" >

                        <?php echo $form['keyword']->render();?>
                <?php echo $form['keyword']->renderError() ?>
                </div>
                    <div class="select-wrapper" data-icon="&#710;">

                   <?php echo $form['volume']->render();?>
                   <?php echo $form['volume']->renderError() ?>
                    </div>
                    <div class="select-wrapper" data-icon="&#710;" >
                                    <?php echo $form['issue']->render();?>
                <?php echo $form['issue']->renderError() ?>

                    </div>
                <div class="search_button">
                <button class="msg_submit_btn" id="fpost" type="submit"></button>
                </div>
        </form>
<?php foreach ($results as $result): ?>
.....
最后在ResultSearch模板中:

            <form id="form_content" method="post" action="<?php echo url_for('@ResultSearch')  ?>">
                <?php echo $form->renderHiddenFields(); ?>

            <?php if($form->hasGlobalErrors()): ?>
            <ul class="error_list">
                <?php foreach($form->getGlobalErrors() as $name => $error): ?>
                <li><?php echo $error; ?></li>
                <?php endforeach; ?>
            </ul>
           <?php endif; ?>
                <div class="search_word" >

                        <?php echo $form['keyword']->render();?>
                <?php echo $form['keyword']->renderError() ?>
                </div>
                    <div class="select-wrapper" data-icon="&#710;">

                   <?php echo $form['volume']->render();?>
                   <?php echo $form['volume']->renderError() ?>
                    </div>
                    <div class="select-wrapper" data-icon="&#710;" >
                                    <?php echo $form['issue']->render();?>
                <?php echo $form['issue']->renderError() ?>

                    </div>
                <div class="search_button">
                <button class="msg_submit_btn" id="fpost" type="submit"></button>
                </div>
        </form>
<?php foreach ($results as $result): ?>
.....

.....
例如,在我的搜索tempalte中,当我在表单中保留关键字字段为空并单击submit时,会将我重定向到结果搜索,而不显示“错误验证”==>“需要关键字”

当我放置var_dump时,我注意到在Resultsearch操作中,代码也停在这里
if($this->form->isValid())

有什么想法吗

编辑:


我注意到,当我在“搜索模板”上面的代码中只使用一个页面时,这意味着post方法在同一个页面中重定向
,因此表单的验证工作正常,但不是我所希望的,我希望在提交后重定向,并将搜索数据传递到上面代码中的另一个页面是“Resultsearch”模板。

您是否确实在结果页面中显示了潜在的表单错误?无论如何,在我看来,这不是最好的工作流程。当您的表单出现错误时,您将显示结果页面,而不显示任何结果,并且用户无法更正错误。我要做的是将表单提交到显示表单的同一个操作,如果表单有效,则重定向到结果页面,否则再次显示表单以及错误信息。否如果您看到上面的代码,我将表单放在“SearchSuccess.php”中那么它在同一个页面中进行验证,但是搜索信息将默认使用post方法发送到“ResultSearchSuccess.php”中?