1

I have a pretty complex form, on which fields are getting enabled and disabled conditionally. I'm using JavaScript to do that without call to server for performance purposes.

How can I not save values from fields that are disabled? Some of the conditions are not entirely based on field values, but also on user's behavior on a form, so it is not possible to simply recreate logic in PHP.

Currently I'm emptying disabled fields before submit, and then testing if $form_state['values']['field'] is filled and $form_state['input']['field'] is empty. If so, I assume field also got disabled, as my script does not allow to submit empty enabled fields. This gives me workable approximation of what I need, but prevents me from implementing graceful degradation for no-js clients, so I need a better solution.

2
  • I don't know how to bite it. Tried to ask on chat for directions, but no success either. Would gladly show what I have tried, but I can't think of any other way that the one in question. – Mołot Nov 25 '13 at 13:06
  • "Some of the conditions are not entirely based on field values, but also on user's behavior on a form" - my first suggestion would be to add hidden fields that capture this user behavior so the logic /can/ be mimicked server-side. – Alfred Armstrong Nov 25 '13 at 13:28
1

There's not really enough information in the question to provide a definitive answer but what I'd suggest is:

  1. add one or more hidden fields to the form to hold state information
  2. store values in the field(s) using javascript when the state of the form changes with user action
  3. On the server side, use the value(s) from the hidden field(s) to represent the state of the form so you can employ them in validation logic.

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.