简体   繁体   English

Symfony2 - 提交后重置表单域

[英]Symfony2 - Reset form field after submission

I wonder whether there is a simple way to reset one of the form fields after form submission and then pass the form to the view - to render the same form but one of the field will be with it's default value.我想知道是否有一种简单的方法可以在提交表单后重置其中一个表单字段,然后将表单传递给视图 - 呈现相同的表单,但其中一个字段将使用它的默认值。 Something like:就像是:

$form = $this->createForm('MyForm');
$form->handleRequest($request);
if ($form->isValid()) {
    // do something
    // ...

    // reset one of the form field to it's default value
    // something like:
    // $form->field->reset() or
    // $form->field->setValue('');
}

return array(
    'form' => $form->createView(),
);

Thanks!谢谢!

You can use:您可以使用:

$form->get('field')->submit($defaultValue);

Check out the doc .查看文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM