[英]How to un-embed form in symfony?
$twoform = new TwoForm;
$this->embedForm('twoform', $twoform);
if($value == false) {
// unembedForm twoform HOW?
}
how can i make if $value == false
then form twoform
is not submit and not add to database?如果$value == false
那么表单twoform
不提交也不添加到数据库中,我该怎么做? unset fields not working, because form is sending, but it has a NULL
value.未设置的字段不起作用,因为表单正在发送,但它具有NULL
值。
You can do this to unset form你可以这样做来取消表格
unset($this->widgetSchema['twoForm']); unset($this->validatorSchema['twoForm']); unset($this->formFieldSchema['twoForm']);
But this won't avoid posting the form in cas it was previously visible.但这不会避免在以前可见的情况下发布表单。 You can replace validator to ignore posted values.您可以替换验证器以忽略发布的值。 $this->setValidator('twoForm', new sfValidatorPass());
If the exemple given is complete, the better is imho not to embed the form if $value == false如果给出的例子是完整的,最好不要嵌入表格 if $value == false
The database insertion depends on how your data is saved into it (sfDoctrineForm?)数据库插入取决于您的数据如何保存到其中(sfDoctrineForm?)
I think you just need to override form bind method:我认为您只需要覆盖表单绑定方法:
public function bind(array $taintedValues = null, array $taintedFiles = null) {
if ($value) {
unset($this['twoForm']); // UNSET embedded form
}
parent::bind($taintedValues, $taintedFiles);
}
Here $value may be form option (use $this->getOption('option_name') for this) or some value from the post query (ie $taintedValues['widget_name']).这里的 $value 可能是表单选项(为此使用 $this->getOption('option_name'))或来自 post 查询的某个值(即 $taintedValues['widget_name'])。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.