Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all fields names from a Symfony's Form

Tags:

forms

php

symfony

For a project I need to check if all form's fields are present in a PUT request.

Simple data validation with the NotNull / NotBlank constraints is not appropriate because the fields in the request can be set with NULL or blank values but they have to be present.

My idea is to take all names from a Form's field and check if those fields are present in the request array.

To do the trick I need to get names of those fields, there's an array in the Form class named orderedKeys which contains exactly what I want, but the variable is set to private.

Is there any other way to get access to those keys ?

like image 951
Thotful Avatar asked Sep 17 '14 08:09

Thotful


1 Answers

You can get all the child forms of a form by doing

$form->all();

Then you can recover the name of each field by doing

$child->getName();
like image 55
Erik Avatar answered Nov 08 '22 12:11

Erik