简体   繁体   中英

Symfony 1.4 form binding problems

I've been browsing for answers for a while and I've given in to asking a question here. I have several working sf forms, but for some reason this one doesn't want to do it. I have a feeling I am missing a small detail I've been lucky to overlook without errors in the past.

Here is the schema:

public function configure()
{

  //widgets
  $this->setWidgets(array(
    'study_area' => new sfWidgetFormSelect( array( 'label' => 'Select Study Area', 'choices' => self::study_areas() )),
    'degree_level' => new sfWidgetFormSelect( array( 'label' => 'Select Degree Level', 'choices' => self::degree_levels() )),
    'campusonline' => new sfWidgetFormSelectRadio( array( 'choices' => self::campus_online(), 'class' => 'radiolabel' )),
    'zip' => new sfWidgetFormInputText( array( 'label' => 'Zip code:')),
  ));

  //validators
  $this->setValidators(array(
    'study_area'   => new sfValidatorString( array( 'required' => true )),
    'degree_level' => new sfValidatorString( array( 'required' => true )),
    'campusonline' => new sfValidatorString( array( 'required' => true )),
    'zip'          => new sfValidatorString(array( 'required' => 'Please enter a valid zip.' )),
  ));

  //formatting, default values, name format, etc
  $this->getWidgetSchema()->getFormFormatter()->setRowFormat( '%label%%error%%field%%help%%hidden_fields%' );
  $this->setDefaults( array( 'study_area' => '', 'degree_level' => '', 'campusonline' => 1 ));
  $this->getWidgetSchema()->setLabel( 'campusonline', false );
  $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
  $this->validatorSchema['zip'] = new sfValidatorZip(array('required' => true));

}

And here is the action:

$this->form = new SearchWidgetForm();

if ($request->isMethod( 'post' ))
{
  $this->form->bind($request->getParameter( 'searchwidget' ));

  if ($this->form->isValid())
  {
    $this->redirect('@search_widget');
  }
  else
  {
    print 'nope';
    $this->form->debug();
    var_dump($request->getParameter( 'searchwidget' ));
    die;
  }
}

And here is what results from that else :

nope
study_area: Required.

degree_level: Required.

campusonline: Required.

zip: Required.

_csrf_token: Required.

null

I have also checked that var_dump( $this->form->isBound() ); produces 'true', which it does. So... The form is bound, but the array it should have become is null.

Any ideas?

Thanks in advance for any help. I would really appreciate it.

I'm only guessing here, (haven't used sf1.x in a bit) but maybe you need to set the form name format? I see you mentioned it in the last comment in your first code snippet, but I don't see the actual line:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM