2014-11-16 32 views
0

我已經創建了一個表單,並且我正在使用驗證,但是每當我點擊提交時,它都不會重定向並顯示相同的頁面。即使我已經設置了默認值, 。 請幫助我。 即使我已經檢查了各種形式沒有幫助。symfony中的isvalid()函數總是給出錯誤

registration form class 

    class registrationform extends sfForm { 
     //put your code here 
     protected static $option=array('Lab Technician','Lecturur','Assistant Professor','Professor','H.O.D'); 
     public function configure() { 

      $this->setWidgets(array(
       'first_Name'=>new sfWidgetFormInputText(array('default'=>'hello'),array('class' => 'textView'),array('default'=>'hello')), 
       'middle_Name'=>new sfWidgetFormInputText(array('default'=>'hello'),array('class' => 'textView')), 
       'last_Name'=>new sfWidgetFormInputText(array('default'=>'hello'),array('class'=>'textView')), 

       'age'=>new sfWidgetFormInputText(array('default'=>'hello'),array('class'=>'textView')), 




      )); 


     $this->setValidators(array(
      'first_Name' => new sfValidatorString(array('required' => 'The message field is required.')), 
      'middle_Name' => new sfValidatorString(array('required' => 'The message field is required.')), 
      'last_Name' => new sfValidatorString(array('required' => 'The message field is required.')), 

      'age' => new sfValidatorString(array('required' => 'The message field is required.')), 

      )); 
     $this->widgetSchema->setNameFormat('contact[%s]'); 
     } 


    ****action.class.php**** 

這是我有我的行動類代碼的類。

public function executeIndex(sfWebRequest $request) 
     { 
     // $this->forward('default', 'module'); 
     $this->registration_form = new registrationform(); 

     if ($request->isMethod('POST')) 
     { 
      $this->registration_form->disableLocalCSRFProtection(); 
      $this->registration_form->bind($request->getParameter('contact')); 


      if (!($this->registration_form->isValid())) 
      { 
       echo"\hiol"; 
      $this->redirect('registration/thankyou?'.http_build_query($this->registration_form->getValues())); 
      } 
     } 


indexsuccess 


<?php echo stylesheet_tag('form');?> 

<div class="page"> 
<div class="form" > 
    <form action="<?php echo url_for('registration/index') ?>" method="POST"> 
    <div class="row" id="head"> 
     REGISTRATION FORM 
    </div> 
    <div class="row"> 
    <div class="columnLabel"><?php echo $registration_form['first_Name']->renderLabel()?></div> 
    <div class="columnView"><?php echo $registration_form['first_Name']->render()?></div> 

    </div> 
     <div class="row"> 
      <div ><?php echo $registration_form['first_Name']->renderError()?></div> 
     </div> 
    <div class="row"> 
    <div class="columnLabel" ><?php echo $registration_form['middle_Name']->renderLabel()?></div> 
    <div class="columnView" ><?php echo $registration_form['middle_Name']->render()?></div> 
    </div> 
    <div class="row"> 
    <div class="columnLabel"><?php echo $registration_form['last_Name']->renderLabel()?></div> 
    <div class="columnView"><?php echo $registration_form['last_Name']->render()?></div> 
    </div> 


    <div class="row"> 
    <div class="columnLabel"><?php echo $registration_form['age']->renderLabel()?></div> 
    <div class="columnView"><?php echo $registration_form['age']->render()?></div> 
    </div> 
    <div class="row"> 
      <div class="columnLabel"><input class="button" type="submit" value="submit" name="submit"></div> 
     </div> 
    </form> 
     </div> 
<!--  </div> 
     </div> 
    </div> 

    </div> 
</div>--> 

回答

1

如果您的操作類有效,則不會保存表單。您應該保存和重定向,如果表單是有效的:

if ($this->registration_form->isValid()) 
{ 
    $this->registration_form->save(); 
    $this->redirect('registration/thankyou'); 
} 

如果您需要下頁表格值,不通過他們的網址,但閃存來代替:

$this->getUser()->setFlash('registration_form', $this->registration_form->getValues());