Forms symfony 1.4失败后从字段重置值
如何重置formfield值Forms symfony 1.4失败后从字段重置值,forms,symfony1,action,field,reset,Forms,Symfony1,Action,Field,Reset,如何重置formfield值 action: $this->form = new $class(); $this->form->bind($request->getParameter('signin')); if ($this->form->isValid()) { $values = $this->form->getVa
action:
$this->form = new $class();
$this->form->bind($request->getParameter('signin'));
if ($this->form->isValid())
{
$values = $this->form->getValues();
$this->redirect('@example');
}
else
{
if ($this->form->hasGlobalErrors())
$this->errorclass = 'error';
}
$this->form->resetFormFields();
return $this->renderPartial('ajax/example);
我有两个字段email和pw:希望在错误为空后重置它们
这不管用:(
有什么解决办法吗?
Thx关于如果您的表单只有两个字段(email和pw),您可以简单地重新输入表单
else
{
if ($this->form->hasGlobalErrors())
$this->errorclass = 'error';
$this->form = new $class();
}
如果您的表单有更多字段(不仅仅是email和pw),并且希望保留其他字段值,则可以删除email和pw值并绑定新表单
$values = $request->getParameter('signin');
$this->form->bind($values);
if ($this->form->isValid())
{
$this->redirect('@example');
}
else
{
if ($this->form->hasGlobalErrors())
$this->errorclass = 'error';
$values['pw'] = '';
$values['email'] = '';
$this->form = new $class();
$this->form->bind($values);
}
$values = $request->getParameter('signin');
$this->form->bind($values);
if ($this->form->isValid())
{
$this->redirect('@example');
}
else
{
if ($this->form->hasGlobalErrors())
$this->errorclass = 'error';
$values['pw'] = '';
$values['email'] = '';
$this->form = new $class();
$this->form->bind($values);
}