如何合并和处理 2 个 symfony 表单? [英] How to merge and handle 2 symfony forms in one?

查看:28
本文介绍了如何合并和处理 2 个 symfony 表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两种 symfony 形式:

I have 2 symfony forms:

SignupFormTypeHouseRentFormType

注册表单看起来像:

<form ..>
<input name='email' .. />
<input name='pass' .. />
..
</form>

房屋租金表格如下:

<form ..>
<input name='city' .. />
<input name='price' .. />
</form ..>

我想将它们组合起来,使它们看起来像这样:

I want to combine them so they look like this:

<form ..>
// house rent info:
<input name='city' .. />
<input name='price' .. />

//registration info:
<input name='email' .. />
<input name='pass' .. />
<input type='submit' />
</form ..>

还可以创建表单类型或 smthng.关于如何处理提交的任何提示?

And also to create a form type or smthng. Any tips on how to handle the submit?

附言我正在使用 symfony/form: ^3.0

p.s. I'm using symfony/form: ^3.0

推荐答案

使用 Symfony 表单,一切都是表单类型.所以一个 from 有一个根类型,有子类型.每个子类型可以有其他子类型,等等.

With Symfony forms, everything is a form type. So one from has a root type, with child types. Each child type can have other child types, etc.

因此,在这种情况下,您有 2 种表单类型:SignupFormTypeHouseRentFormType.您可以将这些用作新表单的子类型:

So in this case, you have 2 form types: SignupFormType and HouseRentFormType. You can use these as child types of a new form:

$form = $formBuilder
    ->add('signup', SignupFormType::class)
    ->add('house_rent', HouseRentFormType::class)
    ->getForm();

这篇关于如何合并和处理 2 个 symfony 表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆