dsbruqxgt820011351 2011-07-19 00:22
浏览 26
已采纳

Symfony 1.4表单绑定问题

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.

  • 写回答

1条回答 默认 最新

  • dongxia527680 2011-07-19 00:31
    关注

    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]');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化