2010-09-18 69 views
0

我正在使用sfExtraForm插件驗證碼在symfony中構建一個簡單的表單郵件程序。除sfValidator之外的所有工作都不會重定向用戶,並在任何字段無效時顯示錯誤。我能想到的唯一的事情是我沒有生成模塊。我從頭開始構建它。我不得不手動重定向。這是因爲這是一個sfForm而不是一個sfDoctrine表單?這是if if($ form-> isValid())行返回false但沒有關聯的重定向和錯誤代碼。這是該計劃。感謝:symfony驗證碼錯誤重定向

形式:

<?php 
class AdsForm extends sfForm 
{ 
    public function configure() 
    { 
    $this->setWidgets(array(
     'name' => new sfWidgetFormInputText(), 
     'email' => new sfWidgetFormInputText(), 
     'phone' => new sfWidgetFormInputText(), 
     'fax' => new sfWidgetFormInputText(), 
     'attention' => new sfWidgetFormInputText(), 
     'message' => new sfWidgetFormInputText(), 
     'captcha' => new sfWidgetFormReCaptcha(array('public_key'=>self::PUBLIC_KEY)), 
    )); 

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

    $this->setValidators(array(
     'name' => new sfValidatorString(array('max_length' => 50)), 
     'email' => new sfValidatorString(array('max_length' => 50)), 
     'phone' => new sfValidatorString(array('max_length' => 50)), 
     'fax' => new sfValidatorString(array('max_length' => 50)), 
     'attention' => new sfValidatorString(array('max_length' => 50)), 
     'message' => new sfValidatorString(array('max_length' => 255)), 
     'captcha' => new sfValidatorReCaptcha(array('private_key' => self::PRIVATE_KEY)) 
    )); 

    $this->widgetSchema->setLabels(array(
     'name' => 'Your Name:*', 
     'email'  => 'Your Email:*', 
     'phone' => 'Your Phone:*', 
     'fax' => 'Your Fax', 
     'attention' => 'Attention:*', 
     'message' => 'Mail Message:*', 
     'captcha' => 'Image Verification:*', 
    )); 
    } 
} 

操作:

class adsActions extends sfActions 
{ 
    public function executeIndex(sfWebRequest $request) 
    { 
     $this->form=new adsForm(); 
    } 
    public function executeSend(sfWebRequest $request){ 

    $this->forward404Unless($request->isMethod(sfRequest::POST)); 


    $form=new adsForm(); 
    $captcha = array('recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'),'recaptcha_response_field' => $request->getParameter('recaptcha_response_field'),); 

    $form->bind(array_merge($request->getParameter('ads'), array('captcha' => $captcha))); 
    if ($form->isValid()) 
    { 
     print_r($_REQUEST); 
     $ads=$this->getRequestParameter('ads'); 
     print_r($ads); 
     $headers = 'From: '."\r\n" . 
     'Reply-To: [email protected]' . "\r\n" . 
     'X-Mailer: PHP/' . phpversion(); 
     //mail(' ******@yahoo.com','Yellow Explorer','An account has been created for you at yellowexplorer.com with a username of '.$this->username.'. Please click <a href="http://yellowexplorer.itecode.com/user/ConfirmRegistration?username='.$this->username.'&key='.$this->key.'">here</a> to finish creating your account.',$headers); 
    } 
    else{ 
     $this->redirect('/ads'); 
    } 
    } 
} 
+0

好的抱歉。不知道你必須打勾。我接受了我過去的問題,並會接受這個問題。 – 2010-09-18 12:02:40

回答

0

你沒有看到任何錯誤,因爲你要重定向!要渲染帶有錯誤的表單字段,您需要呈現您調用綁定的實際表單實例。嘗試將$this->redirect('/ads')更改爲$this->setTemplate('index')

其他潛在的變化(這個問題的範圍之外):

  • 可以實施的路由層發送動作的請求方法的要求。使發送路徑爲sfRequestRoute並添加要求{ sf_method: post }
  • Symfony有一個內置的郵件,sfMailer。任何你決定不使用它的理由?
+0

工作。謝謝 – 2010-09-19 15:51:27