views:

609

answers:

1

Hi, i have some difficulties in understanding why my symfony form doesn't bind properly with the data from request...

The action:

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);
  }

Form class:

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();
   }
}

When entering the action the $request->getParameter('email_form') contains:

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

so it look correct but nevertheless binding fails because $this->form->getValues() returns empty array() and i don't know why ;s ?! Any suggestions ? Thx in advance

A: 

Your form class seems fine.

Try this in your action:

$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'];
Tom