1

I have altered the login form like

if (form_id == 'user_login_form') {
    form.submit.push('my_module_user_login_submit');
  }

In submit I need the uid.

function my_module_user_login_submit(form, form_state) {
   //I need the uid of login user here;
  if(form_state.values.name){
   form.action = 'user-dashboard/'+ uid;
   }
}

Tried

var uid = Drupal.user.uid; but not working.

More info

function my_module_menu() {
var items = {};
items['user-dashboard/%'] = {
    title: 'User dashboard',
    page_callback: 'my_module_user_dashboard_page',
    page_arguments: [1],
    pageshow: 'my_module_user_dashboard_pageshow'
  };
return items;
}


**
 * The user dashboard page callback.
 * @param uid
 * @returns {{}}
 */
function my_module_user_dashboard_page(uid) {
  var content = {};

  // Build an empty container where the user dashboard will go.
  var attributes = {
    id: my_module_user_dashboard_container_id(uid),
    class: 'user-dashboard'
  };
  content['my_widget_container'] = {
    markup: '<div ' + drupalgap_attributes(attributes) + '>' +
      'Loading dashboard...' +
    '</div>'
  };

  return content;
}

/**
 * The user dashboard pageshow event handler.
 * @param uid
 */
function my_module_user_dashboard_pageshow(uid) {
alert(Drupal.user.uid);
  // Load the user account...
  user_load(uid, {
    success: function(account) {
    var content = {};
    content['txt'] = {
        markup: '<div>' + account.name + '</div><div>' + account.uid + '</div>'
    };



      // Inject it into the container.
      var container_id = my_module_user_dashboard_container_id(uid);
      $('#' + container_id).html(drupalgap_render(content)).trigger('create');

    }
  });
}

function my_module_user_dashboard_container_id(uid) {
  return 'user-dashboard-' + uid;
}
1

Try using this hook in your app: http://api.drupalgap.org/7/global.html#hook_services_postprocess

/**
 * Implements hook_services_postprocess().
 */
function my_module_services_postprocess(options, result) {
  if (options.service == 'user' && options.resource == 'login') {
    drupalgap_goto('user-dashboard/'+ Drupal.user.uid);
  }
}

You may also need to set the action on the form object to null so that DrupalGap core doesn't try to redirect the page to the path indicated by the form's action variable:

/**
 * Implements hook_form_alter().
 */
function my_module_form_alter(form, form_state, form_id) {
  if (form_id == 'user_login_form') {
    form.action = null;
  }
}
2
  • Try using a hook_form_alter() in DrupalGap to set the action on the form to null. Apr 27 '17 at 14:00
  • Sure. I've updated my answer with an example of hook_form_alter(). Apr 27 '17 at 14:53

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.