2010-03-01 4 views
0

난 ... 내 심포니 양식 요청에서 데이터를 제대로 결합하지 않는 이유를 이해하는 데 어려움이심포니 양식 바인딩 문제 : 빈 배열

액션 :

public function executeSendEmail(sfWebRequest $request) 
    { 
     $history_id = $request->getParameter('id'); 

     if($request->isMethod(sfRequest::POST)) 
     { 
      print_r("POST"); 

      $this->form = new SendEmailForm(); 

      $this->form->bind($request->getParameter('email_form')); 
      print_r($request->getParameter('email_form')); 

      if(!$this->form->isBound()) 
        die('!isBound()'); 

      print_r($this->form->getValues()); 

      if($this->form->isValid()) 
      { 
       die('form is Valid!'); 
      } 
      die('after isValid...'); 
     } 

     die('redirect !'); 

     $this->redirect('history/show?id='.$history_id); 
    } 

양식 클래스 : 행동 입력시

class SendEmailForm extends sfForm 
{ 
    public function setup() 
    { 
    $this->setWidgets(array(
     'author' => new sfWidgetFormInputText(), 
     'email' => new sfWidgetFormInputText(), 
     'subject' => new sfWidgetFormInputText(), 
     'body' => new sfWidgetFormTextarea(), 
    )); 

    $this->setValidator('email', new sfValidatorEmail()); 


    $this->widgetSchema->setLabels(array(
      'author' => 'Autor', 
      'email' => 'E-mail', 
      'subject' => 'Tytuł', 
      'body' => 'Treść wiadomości' 
    )); 

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

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema); 

    parent::setup(); 
    } 
} 

$request->getParameter('email_form')가 포함

Array ( 
     [author] => RRr 
     [email] => [email protected] 
     [subject] => rrrr 
     [body] => rrrr 
     [_csrf_token] => 73881c1b6217e221c4d25c065ec93052) 

그래서 올바른 것으로 보이지만 $this->form->getValues()이 빈 배열()을 반환하고 왜 그 이유가 알 수 없기 때문에 바인딩에 실패합니다. 제안 사항이 있으십니까? Thx를 미리

답변

1

당신의 폼 클래스는 괜찮아 보입니다.

은 당신의 행동이 시도 :

$this->form = new SendEmailForm(); 
if($request->isMethod('post')) 
{ 
    $this->form->bind($request->getParameter('email_form')); 
    if($this->form->isValid()) 
    { 
     $values = $this->form->getValues(); 
     var_dump($values['author']); 
2

당신은 양식이 유효한지 확인 후 getValues()을 사용해야합니다. 그렇지 않으면 in은 빈 배열을 반환합니다.

0

bind() 메서드는 다음과 같은 작업을 수행하므로 양식이 유효하지 않은 경우 빈 배열이 표시됩니다.

try 
{ 
    $this->doBind(...); 
    ... 
} 
catch (sfValidatorErrorSchema $e) 
{ 
    $this->values = array(); //here 
    $this->errorSchema = $e; 
} 
2
당신은 오류가 같은 무엇을보고 테스트 할 수 있습니다

:

if($this->form->hasErrors()) 
    { 
    echo $this->form->renderGlobalErrors(); 
    } 

이 폼을 직접 생성보다는 심포니 도우미를 사용하는 경우, 당신이 포함되지 않았을 수 있습니다/장애인 csrf 토큰.