I would like to know if there is a way to simply not save elements from a form. I know that we can hide elements with hide(), or #type = hidden/value, etc., but I would like to remove then completely from the form saving process.

I'm building a lot of "partial" forms (small part from a big one) and every time that I want to build a small form, with 2 fields, Drupal processes 20 fields and I have to hide the others 18 fields. It doesn't make sense for me. I'm sure that Drupal can handle this better than hide and I'm missing something.

Complete form: name, age, city, country, phone
Form #1: name, age
Form #2: city, country

I would like to build a form like the #1 (with name and age only) and save it without loosing the data from city, country and phone BUT without hiding fields, valuing them nor with #access = FALSE.

Let me know if I'm still not clear enough. THANKS!!

  • How about conditionally using unset on form fields in a hook_form_alter function? – AjitS Feb 14 '13 at 5:34
  • What about the disabled attribute for the fields? – enzipher Feb 14 '13 at 6:15
  • Are you creating multi-steps form? – Sithu Feb 14 '13 at 6:59
  • @develkar, with unset I lose the field value. – Fabio Mar 3 '13 at 18:17
  • @enzipher, I can't disable any fields... for example, checkboxes are not able to be disabled. – Fabio Mar 3 '13 at 18:17

Your Answer

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

Browse other questions tagged or ask your own question.