本文整理汇总了PHP中Symfony\Component\Form\FormFactoryInterface::getForm方法的典型用法代码示例。如果您正苦于以下问题:PHP FormFactoryInterface::getForm方法的具体用法?PHP FormFactoryInterface::getForm怎么用?PHP FormFactoryInterface::getForm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormFactoryInterface
的用法示例。
在下文中一共展示了FormFactoryInterface::getForm方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct(Request $request, $type = "form", $data = array(), $options = array())
{
$this->request = $request;
$validator = Validation::createValidatorBuilder();
if (!isset($options["attr"]["name"])) {
$options["attr"]["thelia_name"] = $this->getName();
}
$builder = Forms::createFormFactoryBuilder()->addExtension(new HttpFoundationExtension());
if (!isset($options["csrf_protection"]) || $options["csrf_protection"] !== false) {
$builder->addExtension(new CsrfExtension(new SessionCsrfProvider($request->getSession(), isset($options["secret"]) ? $options["secret"] : ConfigQuery::read("form.secret", md5(__DIR__)))));
}
$translator = Translator::getInstance();
$validator->setTranslationDomain('validators')->setTranslator($translator);
$this->formBuilder = $builder->addExtension(new ValidatorExtension($validator->getValidator()))->getFormFactory()->createNamedBuilder($this->getName(), $type, $data, $this->cleanOptions($options));
$this->buildForm();
// If not already set, define the success_url field
// This field is not included in the standard form hidden fields
// This field is not included in the hidden fields generated by form_hidden_fields Smarty function
if (!$this->formBuilder->has('success_url')) {
$this->formBuilder->add("success_url", "hidden");
}
// The "error_message" field defines the error message displayed if
// the form could not be validated. If it is empty, a standard error message is displayed instead.
// This field is not included in the hidden fields generated by form_hidden_fields Smarty function
if (!$this->formBuilder->has('error_message')) {
$this->formBuilder->add("error_message", "hidden");
}
$this->form = $this->formBuilder->getForm();
}