0

我一直在研究在 Symfony 中使用 HTML_QuickForm2 制作的表单,我只知道在 Twig 文件上一次渲染和显示整个表单。我需要在 Twig 布局上分别显示每个字段。

形式

namespace AV\AppBundle\Form;

class ContactForm extends \HTML_QuickForm2 {

    function __construct() {
        parent::__construct('contactform', 'post', array('action' => '', 'name' => "form"));

        $first_name = $fs1->addText('first_name');
        $first_name->setLabel('First Name');
        $first_name->addRule('required', 'This field is required.');

        $last_name = $fs1->addText('last_name');
        $last_name->setLabel('Last Name');
        $last_name->addRule('required', 'This field is required.');

        $company = $fs1->addText('company');
        $company->setLabel('Company');

        $address = $fs1->addTextarea('address');
        $address->setLabel('Address');
        $address->addRule('required', 'This field is required.');

        $city = $fs1->addText('city');
        $city->setLabel('City');
        $city->addRule('required', 'This field is required.');
    }
}

控制器

public function contactAction() {
    $form = new \AV\AppBundle\Form\ContactForm();
    return $this->render('AVAppBundle:Contact:index.html.twig', array('form'=>$form));
}

枝条

{{form|raw}}

此表单一次输出包含所有字段的整个表单的 HTML 内容。但我需要在 Twig/HTML 页面的不同位置分别显示每个字段。我怎样才能做到这一点?

4

0 回答 0