0

I have created a test site using drupal 7.

My requirement is to do an additional operation on user login. I need to redirect the users to another form when the user clicks on login button.

In this form there will be a question and 2 buttons 'update' and 'no'.

If the user chooses update a DB update will happen and also default login action.

But if the user chooses 'no' ,login should not happen.

I have already tried user_login alter, multi-step forms and confirm_form. But nothing seems to be working. Can anyone help.?

  • So you want to force user to Update , or he/she is not able to login? – Alireza Tabatabaeian Dec 5 '15 at 12:42
  • yes. That is what I am trying to achieve – vipin p Dec 5 '15 at 12:45
  • Why don't you provide an agreement check-box in login button itself? should this action happens only one time? – Alireza Tabatabaeian Dec 5 '15 at 12:47
  • no i need to do this in a separate form. – vipin p Dec 5 '15 at 12:49
  • are you familiar with module development in drupal? I can send you some codes about how to redirect and logout if you can build up the form yourself – Alireza Tabatabaeian Dec 5 '15 at 12:55
1

You can make your own login form (or alter default login form, i think) with two submit buttons calling different callback functions:

function xxx_login_form($form, &$state) {

  // .. usename and password fields here

  $form['submit_update'] = array(
    '#type' => 'submit',
    '#value' => t('Update'),
    '#submit' => array('xxx_login_submit_update'),
  );

  $form['submit_no'] = array(
    '#type' => 'submit',
    '#value' => t('No'),
    '#submit' => array('xxx_login_submit_no'),
  );

  return $form;

}

function xxx_login_submit_update($form, &$state) {

      if(user_authenticate($state['values']['username'], $state['values']['password'])) {
        // log in user
        $user_obj = user_load_by_name($username);
        $form_state = array();
        $form_state['uid'] = $user_obj->uid;      
        user_login_submit(array(), $form_state);

        // .. do some updates

        return true;
      } else {
        return false;
      }

}

function xxx_login_submit_no($form, &$state) {

   // do what you need but do not log user in.

}

You can of course add custom validate functions, messages or what you need. If you want redirect to another page after button is pressed, you can use

'#action' => 'some/page/1'

for the buttons.

| improve this answer | |
0

Login Toboggan provides that feature along with many other useful ones.

| improve this answer | |
  • I prefer custom code than using a contributed module – vipin p Dec 5 '15 at 12:21
  • Well then you'll likely achieve that altering the native login form, adding your custom fields, custom validation and custom submit functions – Kojo Dec 5 '15 at 12:34
0

There are number of contributed module (like Login Toboggan) for such functionality but don't want to use contributed module. So you can do it with the help Rules and a custom module (to display confirmation form). You can also combine the rule in your custom module.

| improve this answer | |

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