All form items in Drupal must be created with Form API, otherwise form values in $form_state and in $_POST variables are empty after submitting the form.

But sometimes I need to have in form some other items, not created with Form API. For example I want to use external jquery plugin like Pickadate (similar like datepicker). This js plugin adds some HTML form elements into object. And many other js plugins creates their own form elements on client side.

But when I use these plugins, form sent empty values after submitting. So before submitting the form, I need to remove these custom elements from form. I don't need values from these elements, they just help to pick the value selected by user.

Is there any workaround, some event, that can help me remove these elements right before submitting the form?

1 Answer 1


There are two ways, actually:

  • Wrap them into a proper modules. You will avoid conflict with Form API by cooperating with it. See Datepicker's code to get idea how to do it.
  • Create onsubmit javascript event and remove elements with jQuery.
  • onsubmit event does not work. Drupal does not not want to allow create custom on submit listeners. One solution is to create attribute in Drupal.behavior and set property attach. But it works only for fist onlcick event. It would be fine, if Drupal programmers have documented their own code, because Datepicker javascript code is not documented, too. Jun 10, 2013 at 10:00
  • My mistake. using attach in drupal.behavior works. Jun 10, 2013 at 10:10

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.