0

プロジェクトで検索フォームを作成しましたが、検証が機能していないようです:

Filtersearchform :

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>

結果検索アクションで:

 if ($request->isMethod('post'))
{
  $this->form = new FilterSearchForm();
  $this->form->bind($request->getParameter('filterSearch'));
  if ($this->form->isValid())
  {

      $values = $this->form->getValues();

   $keyword = trim($values['keyword']);
   $volume = trim($values['volume']);
   $issue = trim($values['issue']);

   $search= new Issue();

  $object = $search->searchFilter($issue, $volume, $keyword);

      $this->results= $object;   

  }
}   

そして最後に ResultSearch Template で:

<?php foreach ($results as $result): ?>
.....

たとえば、フォームでキーワード フィールドを空のままにして [送信] をクリックすると、検索テンプレートで「エラー検証」==>「キーワードが必要です」を表示せずに結果検索にリダイレクトされます。

var_dump を置くと、コードもif ($this->form->isValid())Resultsearch アクションでここで停止することに注意してください。

何か案が?

編集 :

「検索テンプレート」の上のコードで1ページだけを使用すると、同じページでポストメソッドリダイレクトを意味する<form id="form_content" method="post" action="">ため、フォームの検証は正常に機能しますが、私が望むものではなく、後でリダイレクトしたいと考えています上記のコードで検索のデータを送信して別のページに渡すのが「Resultsearch」テンプレートです。

4

0 に答える 0