Created
August 17, 2011 09:02
-
-
Save yethee/1151134 to your computer and use it in GitHub Desktop.
Custom template for collection form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\FormBuilder; | |
class PersonFormType extends AbstractType | |
{ | |
public function buildForm(FormBuilder $builder, array $options) | |
{ | |
$builder | |
->add('name') | |
->add('addresses', 'collection', array( | |
'type' => new AddressFormType(), | |
'allow_add' => true, | |
)); | |
} | |
public function getName() | |
{ | |
return 'form_person'; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\FormBuilder; | |
class AddressFormType extends AbstractType | |
{ | |
public function buildForm(FormBuilder $builder, array $options) | |
{ | |
$builder | |
->add('city') | |
->add('street'); | |
} | |
public function getName() | |
{ | |
return 'form_address'; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% form_theme form _self %} | |
<form action="{{ app.request.uri }}" method="post"> | |
{{ form_row(form.name, {'label': 'Name:'}) }} | |
<h3>Addresses</h3> | |
{{ form_widget(form.addresses) }} | |
<input type="submit" /> | |
</form> | |
{% block form_address_row %} | |
{{ form_row(form.city, {'label': 'City:'}) }} | |
{{ form_row(form.street, {'label': 'Street:'}) }} | |
{% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% form_theme form _self %} | |
<form action="{{ app.request.uri }}" method="post"> | |
{{ form_row(form.name, {'label': 'Name:'}) }} | |
<h3>Addresses</h3> | |
<div data-prototype="{{ form_row(form.addresses.get('prototype'))|e }}"> | |
{% for child in form.addresses %} | |
{{ form_row(child) }} | |
{% endfor %} | |
</div> | |
<input type="submit" /> | |
</form> | |
{% block form_address_row %} | |
{{ form_row(form.city, {'label': 'City:'}) }} | |
{{ form_row(form.street, {'label': 'Street:'}) }} | |
{% endblock %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment