5

In Drupal's Form API page mentioned both hidden and value will not display to user.

What is the difference between them?

9

With the hidden form element, the HTML output in the form is <input type="hidden" /> (plus other HTML attributes), while with the value form element nothing is output for the form. The value is simply kept in the cache Drupal uses for forms created with the form API, but nothing is sent to the browser. (In other words, the value is kept on the server side.)

Generally, the "hidden" form element is used when the value is used from JavaScript code, but it is not a value editable, or visible in the form.

5

When you define something as hidden it is actually there in the html as an of hidden type. but when you define it as value it is not rendered in the form.

Both values are passed to the form_state the value would be there in the $form_state['values']

I am not sure what would be a use case for the same. May be a value that is internal to the form and does not need to be even a hidden input.

  • It's useful to have when a value is needed when submitting the form (like a record ID), but is otherwise not something that is ever edited. – jgreep Jun 28 '18 at 19:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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