2010-09-18 70 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