I have a page that has a form and uses the ajax submit handler. Can I use this module to handle the ajax submission through js.php??

function ajax_form() {
   return array(
    'email' => array(
      '#type' => 'textfield',
      '#title' => t('Join our Newsletter'),
      '#required' => TRUE,
      '#attributes' => array(
        'placeholder' => t('mail@example.com'),
      ),
    ),
    'submit' => array(
      '#type' => 'submit',
      '#value' => t('Subscribe'),
      '#ajax' => array(
        'callback' => 'demo_form_ajax_submit',
        'wrapper' => 'demo-demo-form',
        'method' => 'replace',
        'effect' => 'fade',
        'event' => 'click'
      ),
    ),
  );
}

Comments

prabeen.giri’s picture

Title: Can I use this module to submit ajax form » Can I use this module with ajax submit form
prabeen.giri’s picture

I have to answer my own question.

Looks like its possible to have form ajax submit submitting to the js.php created by the js module.

We have to specify the ['path'] attribute on ajax parameters.

function ajax_form() {
   return array(
    'email' => array(
      '#type' => 'textfield',
      '#title' => t('Join our Newsletter'),
      '#required' => TRUE,
      '#attributes' => array(
        'placeholder' => t('mail@example.com'),
      ),
    ),
    'submit' => array(
      '#type' => 'submit',
      '#value' => t('Subscribe'),
      '#ajax' => array(
        'path' => 'js/my_module/hook_js_key',
        'callback' => 'demo_form_ajax_submit',
        'wrapper' => 'demo-demo-form',
        'method' => 'replace',
        'effect' => 'fade',
        'event' => 'click'
      ),
    ),
  );
}

Implements hook_js().

function my_module_js() {
 return array(
    'hook_js_key' => array(
      'callback'     => 'my_custom_ajax_form_callback',
    ),
  );
}
// Callback Function 
function my_custom_ajax_form_callback() {
  ajax_deliver(ajax_form_callback());

// Ajax form submit handler. 
function demo_form_ajax_submit(&$form, &$form_state, $form_id) {
  //return ajax_render();
}
prabeen.giri’s picture

Status: Active » Closed (fixed)