简体   繁体   English

将不在架构中的表单字段添加到Doctrine形式的Symfony 1.4中

[英]Adding a form field that is not in the schema to Doctrine form Symfony 1.4

I have an image upload form and at the bottom, I'd like to have a checkbox that the user must check before submitting the form, certifying that they have the right to distribute the photo. 我有一个图片上传表单,在底部,我想要一个用户必须在提交表单之前检查的复选框,证明他们有权分发照片。 I've tried adding it as a Widget in the Form class, but it is not displaying. 我尝试在Form类中将其添加为Widget,但它没有显示。 What is the best way to accomplish this? 完成此任务的最佳方法是什么?

For validation, you can add this to your form class to allow fields outside the model: 对于验证,您可以将其添加到表单类以允许模型外部的字段:

$this->validatorSchema->setOption('allow_extra_fields', true);
$this->validatorSchema->setOption('filter_extra_fields', false); // true or false

Other than that, just adding the widget in the standard way should work fine. 除此之外,只需以标准方式添加小部件应该可以正常工作。

Adding a new widget to your form should be the right way. 向表单添加新窗口小部件应该是正确的方法。

class ImageForm extends BaseImageForm
{
  public function configure()
  {

    $this->widgetSchema['copyright'] = new sfWidgetFormInputCheckbox();
  }
}

For conditional validation, check this cookbook page should still be valid. 对于条件验证,请检查 cookbook页面是否仍然有效。

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

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