0

How do i get field type (e.g textfield, option, etc.) from $form_state in below method.

public function validateForm(array &$form, FormStateInterface $form_state)
4
  • 2
    Can you not get it from $form? It's available right there.
    – Beebee
    Commented Jun 15, 2016 at 14:25
  • See $form_state['fields'] or something like that.
    – user21641
    Commented Jun 16, 2016 at 8:08
  • When you write 'field type' do you mean the entity field type? Or a render element type?
    – Eyal
    Commented Jun 17, 2016 at 11:55
  • @Eyal render element type
    – AnD
    Commented Jun 17, 2016 at 12:00

3 Answers 3

1

As said before, it is in

$form['fieldname']['#type']

You don't need the state for this because it is not a state, it's static.

0

no filed type in $form_state

you can use $form instead

0

The render element types are defined using the #type property in the render array.

The only render element that the form state object (might [1]) reference directly is the main form element, via the getCompleteForm method.

[1] the form builder object sets the complete form parameter on the form state while building the form, so I'm the early stages it might not yet be set.

P.S.

The form state object does hold a reference the form object. Which means that in entity forms, you can get the entity and it's fields from the form state object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.