Reputation: 123
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 ?
Upvotes: 12
Views: 15279
Reputation: 1057
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();
Upvotes: 20