Reputation: 41
I try to render a few fields in my form, not all, but twig always render all fields. It is my twig code:
{{ form_start(form) }}
{{form_widget(form.subject)}}
{{form_widget(form.name)}}
{{form_widget(form.parent,{'value' : ''})}}
{{form_widget(form.save)}}
{{ form_end(form) }}
Upvotes: 4
Views: 1311
Reputation: 1059
Set type for field you don't want visible to hidden. your form type would look something like this:
class ConfigurationFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('email', HiddenType::class)
// more fields
}
// other configurations
}
Upvotes: 1
Reputation: 3479
The form_end
function renders the elements that have not been rendered yet. Read here: http://symfony.com/doc/current/reference/forms/twig_reference.html#form-end-view-variables.
This helper also outputs form_rest() unless you set render_rest to false
You can disable that behaviour as you can see in the docs.
Anyway you should render all fields for validation to work, for example, and for security reasons (as it will add validation for CSRF automatically).
Upvotes: 0