I have a submit button in my form and I want to implement it using ajax:
function myid_user_page_form(){
drupal_add_library('system', 'drupal.ajax');
$form = array();
$form['id'] = array(
'#type' => 'fieldset',
'#title' => t('ID Information'),
'#prefix' => '<div id="myid_search_id_number_wrapper">',
'#suffix' => '</div>'
);
$form['submit'] = array(
'#type' => 'button',
'#value' => 'Save',
'#ajax' => array(
'event' => 'click',
'callback' => 'myid_user_page_form_ajax_submit',
'wrapper' => 'myid_search_id_number_wrapper'
),
'#attributes' => array(
'id' => 'myid_save',
),
);
function myid_user_page_form_ajax_submit($form, &$form_state) {
watchdog('Wow','Wow');
}
After executing the code above, the page still has it's refresh after it's clickfunctionality. The ajax doesnt work and no Wow message log in my watchdog table from my database, which means the ajax callback function isn't called. Where am I missing?
$form['submit']array, then replace#type => 'button'with#type => 'submit'. Also, you should be returning the$formvariable in ahook_form()function. Also, people better at Drupal than myself might know better, but I don't think there's any need to manually include a core Drupal library in your module.