1

My module hade a form and the form have 5 buttons: create, edit, save, etc.. also my module form use ajax to send the requests, and the function look like this:

$form['dialogCreateButton'] = array(
    '#type' => 'button', 
    '#value' => t('Create'),
    '#ajax' => array(
        'callback' => 'form_kalendar_dialog_validate',
        'progress' => array(
            'type' => 'throbber',
            'message' => t('Please wait...'),
        ),
    ),
);
$form['dialogSaveButton'] = array(
    '#type' => 'button', 
    '#value' => t('Save'), 
    '#ajax' => array(
        'callback' => 'form_kalendar_dialog_validate',
        'effect' => 'fade',
    ),
); 

This are only two of the buttons, but it's does't matter much because the problem is in the theme (template) side regarding javascript, not on the server side. In my template file I call the form with: print drupal_render(drupal_get_form('form_kalendar_dialog')); it works fine, but on submit I would like to make some changes on the DOM with jQuery and I need to know witch button fired the form submit!

Drupal.behaviors.rr = {
    attach: function(context, settings) {
        jQuery("#edit-dialogcreatebutton").click(function(event) {
            console.log('dialogcreatebutton');
        });

        jQuery("#edit-dialogsavebutton").click(function(event) {
            console.log('dialogsavebutton');
        });
    },
    detach: function(context, settings){
        jQuery('#dialog').dialog('close');
    }
}

With the above function on detach it close the dialog where the form is, but I would like to find out witch button is the trigger, what is the response of synchronised request made to server (stored in a variable not stored in a tag) and to add event on every button to make new changes on DOM, based on form inputs!

<form action="/?q=kalendar" method="post" id="form-kalendar-dialog" accept-charset="UTF-8"><div><div class="form-item form-type-textfield form-item-event-title">
  <label for="edit-event-title">Event title </label>
 <input id="dialog-event-title" type="text" name="event_title" value="" size="40" maxlength="200" class="form-text">
</div>
<span id="dialog-event-when">When</span><div class="form-item form-type-textfield form-item-event-date">
  <label for="edit-event-date">Sunday, 29 May 2016, 12pm - 12:30pm</label>
 <input id="dialog-event-date" hidden="hidden" data-time="Sunday, 29 May 2016" type="text" name="event_date" value="" size="40" maxlength="120" class="form-text">
</div>
<input type="submit" id="edit-dialogeditbutton" name="op" value="Edit event" class="form-submit ajax-processed"><input type="submit" id="edit-dialogcreatebutton" name="op" value="Create" class="form-submit ajax-processed"><input type="submit" id="edit-dialogsavebutton" name="op" value="Save" class="form-submit ajax-processed" style="display: none;"><input type="submit" id="edit-dialogdeletebutton" name="op" value="Delete" class="form-submit ajax-processed" style="display: none;"><input type="submit" id="edit-dialogdiscardbutton" name="op" value="Discarc changes" class="form-submit ajax-processed" style="display: none;"><input type="hidden" name="form_build_id" value="form-_ivUkOlvspquqr1Bl6rIRULqbj3rmxUXdZiA25-ZFG8">
<input type="hidden" name="form_token" value="SJ3DhMEcrrcT6QkiPJE9EGyjtQ4qCMpuhwkw7zDAvdY">
<input type="hidden" name="form_id" value="form_kalendar_dialog">
</div></form>

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.