1

I have created a form using fields with two action buttons; one for the default submit functionality ('Save'), and the other one for custom submit functionality ('Submit').

When the user clicks the submit button a confirm box is displayed asking the user whether he wants to submit the form or not. If the user selects yes, the custom submit callback for the button should execute.

I am using the jquery-alerts plugin to display a customized confirm box on the click event of 'Submit' button. I used the following jquery code for this

$('#recommendation-letter-node-form #edit-save').click(function() {
  jConfirm("Once you submit the application, you will not be able to modify it any further. Are you sure you want to submit?", "Application Confirmation Dialog", function(confirm) {
    if (confirm) {
      $(this).submit();
    }
  });
  return false;
});

the .submit() function doesn't work for buttons other than default form submit button and I need that the other button submit callback should be triggered when the confirm value is true.

1

One approach I used to achieved this was using the same callback function. Then within this method, use $form_state['triggering_element']['#id'] or something similar to execute the proper function... i.e.

function my_form_submit($form, &$form_state) {
  $id = $form_state['triggering_element']['#id'];

  switch ($id) {
    case 'edit-submit':
      submit_my_form($form, $form_state);
      break;
    case 'edit-save':
      save_my_form($form, $form_state);
      break;
  }
}
1

Your problem is $(this) refered to first button(save button not submit button ), you should change $(this).submit() to $('#yourformid').submit(); .

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.