0

I have an ECK (Entity Construction Kit) form with several required fields. The form contains a series of submit buttons.

The 'complete' button does a regular form submit, triggering the appropriate validation & submit handlers.

The 'save & close' button needs to submit the form & save the data without doing any validation, and this is what I'm having trouble with. I know I can use the #limit_validation_errors property on the 'save & close' button to remove validation, but that also removes the submitted data from $form_state['values'] in the submit handlers.

I tried rebuilding that data in a custom submit handler, re-inserting it into $form_state['values'], and then triggering ECK's original submit handler (which, in theory, should save the data), but that doesn't work:

function my_custom_form_submit($form, &$form_state) {
  if (isset($form_state['values']['no_validation_submit'])) {
    // make copies of the form variables, since they get passed by reference & modified in form_builder();
    $form_copy = $form;
    $form_state_copy = $form_state;

    // rebuild the data to get correct ['values'] in $form_state_copy;
    $form_copy = form_builder($form['#id'], $form_copy, $form_state_copy);

    // place the rebuilt ['values'] into original $form_state & call ECK's submit handler
    $form_state['values'] = $form_state_copy['values'];
    eck__entity__form_submit($form, $form_state);
  }
}

Any ideas for how to achieve this?

0

The solution dawned on me this morning; to get this functionality in place I need to work backwards: rather than having Drupal validate the required fields and conditionally disabling the validation, we should remove the validation requirements from the form, and conditionally add them (doing custom validation, if need be).

So, the #required parameter is set to FALSE for all fields, and a custom validation handler conditionally checks the 'required functionality.'

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.