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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度