Hello
I want to establish a jquery validation for my user connection login block, ie without page refresh in case of connection failure, for example.
But I do not see how to start .
Would you have an idea please ?
Thank you

Comments

Jaypan’s picture

You can add JS to the user login block by implementing hook_form_user_login_block_alter():

function hook_form_user_login_block_alter(&$form, &$form_state)
{
  $form['#attached']['js'][] = array
  (
    'type' => 'file',
    'data' => drupal_get_path('module', 'mymodule') . '/js/user_login_block.js',
  );
}

You can then put your code in the file located at [PATH TO YOUR MODULE]/js/user_login_block.js

In that file you can add your code as follows:

(function($, Drupal)
{
  Drupal.behaviors.myModuleUserLoginBlock = {
    attach:function()
    {
      // Add your validation jQuery here
    }
  };
}(jQuery, Drupal));

You can read more about JavaScript in Drupal 7 here: https://www.drupal.org/node/756722

evets33’s picture

Thank you very much ! i will practice and come back