I am using Drupal 7 to create an registration form, there are: username, email dan password fields, but I want to make an username checking while user leave username field (ajax). I found an module as Username Check
This module is great and working in "myweb/user/register" form, but I need to move this function to my custom form in username field too
The code:
function username_check_menu() {
$items = array();
$items['username_check/isunique'] = array(
'type' => MENU_CALLBACK,
'page callback' => 'username_check_callback',
'access arguments' => array('access content'),
'file' => 'username_check.unique.inc',
);
$items['admin/config/system/username_check'] = array(
'title' => 'Username check',
'type' => MENU_NORMAL_ITEM,
'page callback' => 'drupal_get_form',
'page arguments' => array('username_check_settings'),
'access arguments' => array('administer site configuration'),
'file' => 'username_check.admin.inc',
);
return $items;
}
function username_check_form_user_register_form_alter(&$form) {
$mode = variable_get('username_check_mode', 'auto');
if($mode != 'off')
{
_username_check_load_resources($mode);
$form['account']['name']['#field_suffix'] = '<span id="username-check-informer"> </span>';
$form['account']['name']['#suffix'] = '<div id="username-check-message"></div>';
}
}
/**
* Load username_check resources.
*/
function _username_check_load_resources($mode) {
$module_path = drupal_get_path('module', 'username_check');
drupal_add_css($module_path . '/username_check.css');
drupal_add_js($module_path . '/username_check.js');
drupal_add_js(array(
'usernameCheck' => array(
'ajaxUrl' => url('username_check/isunique', array('absolute' => TRUE)),
'delay' => variable_get('username_check_delay', 1),
),
), 'setting');
}
and my form as userregis_form
How to apply this to my custom form?