I have a javascript code below:

    type: "POST", 
    url: "?q=myid_print/update_table",                                      
}).done(function(o) {

It calls a function declared in my hook_menu:

function myid_print_menu()
    $items = array();       
    $items['myid_print/update_table'] = array(
        'title' => 'ID History',
        'page callback' => 'myid_print_all_submitted_id_callback',                      
        'type' => MENU_CALLBACK,
    return $items;

Below is the function being invoked:

function myid_print_all_submitted_id_callback($form, &$form_state){  
    watchdog('myid_print', 'Wow');
    return $form['table']; 

After looking at my drupal's database, particularly in watchdog table, I saw the message Wow, which indicates that the function myid_print_all_submitted_id_callback has been called but my $form_table is not updated. The obvious reason behind this is I did not pass an argument $form and $form_state. Then, this is what my question is. How will I pass $form and $form_state arguments? Or any way that I could render $form_table invoke by javascript?


If you're using Drupal's form API, it already has support for AJAX built into to it via the #ajax property. For example....

function MYMODULE_example_form() {
  //@TODO: various form elments...

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
    '#ajax' => array(
      'callback' => '_MYMODULE_example_form_submit'
  return $form;

function _MYMODULE_example_form_submit($form, &$form_state) {
  //@TODO: process submitted form

The examples module has more examples of this if you'd like to see more of it in action.

  • Thank you for reminding me, you've always been a great help. – user46175 Sep 9 '15 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy