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 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算