Skip to main content
deleted 3 characters in body
Source Link

I read a lot of documentation, specially this post https://www.drupal.org/node/2009252 but doesnt work for me.

This is my code, and the main problem is that i dont get the javascript in function _hcat_my_account_create_companion_ajax_callbackhcat_my_account_create_companion_ajax_callback from the page callback 'my-account/ajax/create-companion' then I cant send my form by ajax.

function hcat_my_account_menu() {
    $items = array();

    $items['my-account/ajax/create-companion'] = array(
        'page callback' => '_hcat_my_account_create_companion_ajax_callback''hcat_my_account_create_companion_ajax_callback',
        'access callback' => TRUE,
     );

    return $items; 
}

function _hcat_my_account_create_companion_ajax_callbackhcat_my_account_create_companion_ajax_callback($form, &$form_state) {  

    $submission = (object) array();
    $form = render(drupal_get_form('hcat_my_account_acomp_form', null, $submission, true, false));

    $settings = FALSE;
    $javascript = drupal_add_js(NULL, NULL);
    if(isset($javascript['settings'], $javascript['settings']['data'])) {
        $settings = '<script type="text/javascript">jQuery.extend(Drupal.settings, '.drupal_json_encode(call_user_func_array('array_merge_recursive', $javascript['settings']['data'])).'); console.log("He cargado el Drupal.settings");</script>';
    }
    
    form_load_include($form_state, 'inc', 'node', 'node.pages');
//I CANT PASS ANY JAVASCRIPT. WILL DISAPPEAR.
    return "<div id='new-form-ajax'>".$form.$settings."</div>";
}

function hcat_my_account_acomp_form($form, &$form_state, $vars) {

    $form['hola'] = array(
        '#type' => 'textfield',
        '#default_value' => "Vamos",
        '#attributes' => array('class' => array('my-account-input-edit')),
    );
    $form['submit_save'] = array(
          '#type' => 'submit',
          '#value' => 'Vamos que te quda poco',
          '#ajax' => array(
                'callback' => "hcat_my_account_create_attend_form_submit_ajax",
                'wrapper' => "hcat-my-account-acomp-form",
                'method' => 'replace',
                'effect' => 'fade',
              ),
    );

    form_load_include($form_state, 'inc', 'node', 'node.pages');

    return $form;
}

function hcat_my_account_create_attend_form_submit_ajax($form, &$form_state) {
    return "Desde la funcion hcat_my_account_create_attend_form_submit_ajax";
}

I read a lot of documentation, specially this post https://www.drupal.org/node/2009252 but doesnt work for me.

This is my code, and the main problem is that i dont get the javascript in function _hcat_my_account_create_companion_ajax_callback from the page callback 'my-account/ajax/create-companion' then I cant send my form by ajax.

function hcat_my_account_menu() {
    $items = array();

    $items['my-account/ajax/create-companion'] = array(
        'page callback' => '_hcat_my_account_create_companion_ajax_callback',
        'access callback' => TRUE,
     );

    return $items; 
}

function _hcat_my_account_create_companion_ajax_callback($form, &$form_state) { 

    $submission = (object) array();
    $form = render(drupal_get_form('hcat_my_account_acomp_form', null, $submission, true, false));

    $settings = FALSE;
    $javascript = drupal_add_js(NULL, NULL);
    if(isset($javascript['settings'], $javascript['settings']['data'])) {
        $settings = '<script type="text/javascript">jQuery.extend(Drupal.settings, '.drupal_json_encode(call_user_func_array('array_merge_recursive', $javascript['settings']['data'])).'); console.log("He cargado el Drupal.settings");</script>';
    }
    
    form_load_include($form_state, 'inc', 'node', 'node.pages');
//I CANT PASS ANY JAVASCRIPT. WILL DISAPPEAR.
    return "<div id='new-form-ajax'>".$form.$settings."</div>";
}

function hcat_my_account_acomp_form($form, &$form_state, $vars) {

    $form['hola'] = array(
        '#type' => 'textfield',
        '#default_value' => "Vamos",
        '#attributes' => array('class' => array('my-account-input-edit')),
    );
    $form['submit_save'] = array(
          '#type' => 'submit',
          '#value' => 'Vamos que te quda poco',
          '#ajax' => array(
                'callback' => "hcat_my_account_create_attend_form_submit_ajax",
                'wrapper' => "hcat-my-account-acomp-form",
                'method' => 'replace',
                'effect' => 'fade',
              ),
    );

    form_load_include($form_state, 'inc', 'node', 'node.pages');

    return $form;
}

function hcat_my_account_create_attend_form_submit_ajax($form, &$form_state) {
    return "Desde la funcion hcat_my_account_create_attend_form_submit_ajax";
}

I read a lot of documentation, specially this post https://www.drupal.org/node/2009252 but doesnt work for me.

This is my code, and the main problem is that i dont get the javascript in function hcat_my_account_create_companion_ajax_callback from the page callback 'my-account/ajax/create-companion' then I cant send my form by ajax.

function hcat_my_account_menu() {
    $items = array();

    $items['my-account/ajax/create-companion'] = array(
        'page callback' => 'hcat_my_account_create_companion_ajax_callback',
        'access callback' => TRUE,
     );

    return $items; 
}

function hcat_my_account_create_companion_ajax_callback($form, &$form_state) {  

    $submission = (object) array();
    $form = render(drupal_get_form('hcat_my_account_acomp_form', null, $submission, true, false));

    $settings = FALSE;
    $javascript = drupal_add_js(NULL, NULL);
    if(isset($javascript['settings'], $javascript['settings']['data'])) {
        $settings = '<script type="text/javascript">jQuery.extend(Drupal.settings, '.drupal_json_encode(call_user_func_array('array_merge_recursive', $javascript['settings']['data'])).'); console.log("He cargado el Drupal.settings");</script>';
    }
    
    form_load_include($form_state, 'inc', 'node', 'node.pages');
//I CANT PASS ANY JAVASCRIPT. WILL DISAPPEAR.
    return "<div id='new-form-ajax'>".$form.$settings."</div>";
}

function hcat_my_account_acomp_form($form, &$form_state, $vars) {

    $form['hola'] = array(
        '#type' => 'textfield',
        '#default_value' => "Vamos",
        '#attributes' => array('class' => array('my-account-input-edit')),
    );
    $form['submit_save'] = array(
          '#type' => 'submit',
          '#value' => 'Vamos que te quda poco',
          '#ajax' => array(
                'callback' => "hcat_my_account_create_attend_form_submit_ajax",
                'wrapper' => "hcat-my-account-acomp-form",
                'method' => 'replace',
                'effect' => 'fade',
              ),
    );

    form_load_include($form_state, 'inc', 'node', 'node.pages');

    return $form;
}

function hcat_my_account_create_attend_form_submit_ajax($form, &$form_state) {
    return "Desde la funcion hcat_my_account_create_attend_form_submit_ajax";
}
added 45 characters in body
Source Link

I read a lot of documentation, specially this post https://www.drupal.org/node/2009252 but doesnt work for me.

This is my code, and the main problem is that i dont get the javascript in function _hcat_my_account_create_companion_ajax_callback from the page callback 'my-account/ajax/create-companion' then I cant send my form by ajax.

function hcat_my_account_menu() {
    $items = array();

    $items['my-account/ajax/create-companion'] = array(
        'page callback' => '_hcat_my_account_create_companion_ajax_callback',
        'access callback' => TRUE,
     );

    return $items; 
}

function _hcat_my_account_create_companion_ajax_callback($form, &$form_state) { 

    $submission = (object) array();
    $form = render(drupal_get_form('hcat_my_account_acomp_form', null, $submission, true, false));

    $settings = FALSE;
    $javascript = drupal_add_js(NULL, NULL);
    if(isset($javascript['settings'], $javascript['settings']['data'])) {
        $settings = '<script type="text/javascript">jQuery.extend(Drupal.settings, '.drupal_json_encode(call_user_func_array('array_merge_recursive', $javascript['settings']['data'])).'); console.log("He cargado el Drupal.settings");</script>';
    }
    
    form_load_include($form_state, 'inc', 'node', 'node.pages');
//I CANT PASS ANY JAVASCRIPT. WILL DISAPPEAR.
    return "<div id='new-form-ajax'>".$form.$settings."</div>";
}

function hcat_my_account_acomp_form($form, &$form_state, $vars) {

    $form['hola'] = array(
        '#type' => 'textfield',
        '#default_value' => "Vamos",
        '#attributes' => array('class' => array('my-account-input-edit')),
    );
    $form['submit_save'] = array(
          '#type' => 'submit',
          '#value' => 'Vamos que te quda poco',
          '#ajax' => array(
                'callback' => "hcat_my_account_create_attend_form_submit_ajax",
                'wrapper' => "hcat-my-account-acomp-form",
                'method' => 'replace',
                'effect' => 'fade',
              ),
    );

    form_load_include($form_state, 'inc', 'node', 'node.pages');

    return $form;
}

function hcat_my_account_create_attend_form_submit_ajax($form, &$form_state) {
    return "Desde la funcion hcat_my_account_create_attend_form_submit_ajax";
}

I read a lot of documentation, specially this post https://www.drupal.org/node/2009252 but doesnt work for me.

This is my code, and the main problem is that i dont get the javascript in function _hcat_my_account_create_companion_ajax_callback from the page callback 'my-account/ajax/create-companion' then I cant send my form by ajax.

function hcat_my_account_menu() {
    $items = array();

    $items['my-account/ajax/create-companion'] = array(
        'page callback' => '_hcat_my_account_create_companion_ajax_callback',
        'access callback' => TRUE,
     );

    return $items; 
}

function _hcat_my_account_create_companion_ajax_callback($form, &$form_state) { 

    $submission = (object) array();
    $form = render(drupal_get_form('hcat_my_account_acomp_form', null, $submission, true, false));

    $settings = FALSE;
    $javascript = drupal_add_js(NULL, NULL);
    if(isset($javascript['settings'], $javascript['settings']['data'])) {
        $settings = '<script type="text/javascript">jQuery.extend(Drupal.settings, '.drupal_json_encode(call_user_func_array('array_merge_recursive', $javascript['settings']['data'])).'); console.log("He cargado el Drupal.settings");</script>';
    }
    
    form_load_include($form_state, 'inc', 'node', 'node.pages');

    return "<div id='new-form-ajax'>".$form.$settings."</div>";
}

function hcat_my_account_acomp_form($form, &$form_state, $vars) {

    $form['hola'] = array(
        '#type' => 'textfield',
        '#default_value' => "Vamos",
        '#attributes' => array('class' => array('my-account-input-edit')),
    );
    $form['submit_save'] = array(
          '#type' => 'submit',
          '#value' => 'Vamos que te quda poco',
          '#ajax' => array(
                'callback' => "hcat_my_account_create_attend_form_submit_ajax",
                'wrapper' => "hcat-my-account-acomp-form",
                'method' => 'replace',
                'effect' => 'fade',
              ),
    );

    form_load_include($form_state, 'inc', 'node', 'node.pages');

    return $form;
}

function hcat_my_account_create_attend_form_submit_ajax($form, &$form_state) {
    return "Desde la funcion hcat_my_account_create_attend_form_submit_ajax";
}

I read a lot of documentation, specially this post https://www.drupal.org/node/2009252 but doesnt work for me.

This is my code, and the main problem is that i dont get the javascript in function _hcat_my_account_create_companion_ajax_callback from the page callback 'my-account/ajax/create-companion' then I cant send my form by ajax.

function hcat_my_account_menu() {
    $items = array();

    $items['my-account/ajax/create-companion'] = array(
        'page callback' => '_hcat_my_account_create_companion_ajax_callback',
        'access callback' => TRUE,
     );

    return $items; 
}

function _hcat_my_account_create_companion_ajax_callback($form, &$form_state) { 

    $submission = (object) array();
    $form = render(drupal_get_form('hcat_my_account_acomp_form', null, $submission, true, false));

    $settings = FALSE;
    $javascript = drupal_add_js(NULL, NULL);
    if(isset($javascript['settings'], $javascript['settings']['data'])) {
        $settings = '<script type="text/javascript">jQuery.extend(Drupal.settings, '.drupal_json_encode(call_user_func_array('array_merge_recursive', $javascript['settings']['data'])).'); console.log("He cargado el Drupal.settings");</script>';
    }
    
    form_load_include($form_state, 'inc', 'node', 'node.pages');
//I CANT PASS ANY JAVASCRIPT. WILL DISAPPEAR.
    return "<div id='new-form-ajax'>".$form.$settings."</div>";
}

function hcat_my_account_acomp_form($form, &$form_state, $vars) {

    $form['hola'] = array(
        '#type' => 'textfield',
        '#default_value' => "Vamos",
        '#attributes' => array('class' => array('my-account-input-edit')),
    );
    $form['submit_save'] = array(
          '#type' => 'submit',
          '#value' => 'Vamos que te quda poco',
          '#ajax' => array(
                'callback' => "hcat_my_account_create_attend_form_submit_ajax",
                'wrapper' => "hcat-my-account-acomp-form",
                'method' => 'replace',
                'effect' => 'fade',
              ),
    );

    form_load_include($form_state, 'inc', 'node', 'node.pages');

    return $form;
}

function hcat_my_account_create_attend_form_submit_ajax($form, &$form_state) {
    return "Desde la funcion hcat_my_account_create_attend_form_submit_ajax";
}
Source Link

Ajax Forms created by Ajax Drupal 7 ERROR JAVASCRIPT

I read a lot of documentation, specially this post https://www.drupal.org/node/2009252 but doesnt work for me.

This is my code, and the main problem is that i dont get the javascript in function _hcat_my_account_create_companion_ajax_callback from the page callback 'my-account/ajax/create-companion' then I cant send my form by ajax.

function hcat_my_account_menu() {
    $items = array();

    $items['my-account/ajax/create-companion'] = array(
        'page callback' => '_hcat_my_account_create_companion_ajax_callback',
        'access callback' => TRUE,
     );

    return $items; 
}

function _hcat_my_account_create_companion_ajax_callback($form, &$form_state) { 

    $submission = (object) array();
    $form = render(drupal_get_form('hcat_my_account_acomp_form', null, $submission, true, false));

    $settings = FALSE;
    $javascript = drupal_add_js(NULL, NULL);
    if(isset($javascript['settings'], $javascript['settings']['data'])) {
        $settings = '<script type="text/javascript">jQuery.extend(Drupal.settings, '.drupal_json_encode(call_user_func_array('array_merge_recursive', $javascript['settings']['data'])).'); console.log("He cargado el Drupal.settings");</script>';
    }
    
    form_load_include($form_state, 'inc', 'node', 'node.pages');

    return "<div id='new-form-ajax'>".$form.$settings."</div>";
}

function hcat_my_account_acomp_form($form, &$form_state, $vars) {

    $form['hola'] = array(
        '#type' => 'textfield',
        '#default_value' => "Vamos",
        '#attributes' => array('class' => array('my-account-input-edit')),
    );
    $form['submit_save'] = array(
          '#type' => 'submit',
          '#value' => 'Vamos que te quda poco',
          '#ajax' => array(
                'callback' => "hcat_my_account_create_attend_form_submit_ajax",
                'wrapper' => "hcat-my-account-acomp-form",
                'method' => 'replace',
                'effect' => 'fade',
              ),
    );

    form_load_include($form_state, 'inc', 'node', 'node.pages');

    return $form;
}

function hcat_my_account_create_attend_form_submit_ajax($form, &$form_state) {
    return "Desde la funcion hcat_my_account_create_attend_form_submit_ajax";
}