我一直在寻找答案,我已经在这里问了一个问题。我有几个工作的sf表单,但由于某种原因,这个人不想这样做。我有一种感觉,我错过了一个小细节,我很幸运地忽略了过去没有错误。
这是架构:
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));
}
以下是行动:
$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;
}
}
以下是else
:
nope
study_area: Required.
degree_level: Required.
campusonline: Required.
zip: Required.
_csrf_token: Required.
null
我还检查过var_dump( $this->form->isBound() );
生成'true',它确实如此。所以...表单是绑定的,但它应该变成的数组是null。
有什么想法吗?
提前感谢您的帮助。我真的很感激。
答案 0 :(得分:1)
我只是在这里猜测,(有点没用过sf1.x)但是你可能需要设置表单名称格式吗?我看到你在第一个代码片段的最后一条评论中提到过它,但我没看到实际的行:
$this->widgetSchema->setNameFormat('searchwidget[%s]');