Why and Where we need custom override ?
Drupal 7 has its own core functionality for Login, Register & Forgot-Password module. In some project cases there will be need of changing the functionality of these core modules. In that case we should not over write the core modules to achieve the functionality instead we should override the functionality with our custom module.How to custom Validate & Submit functionality for core modules?
To override the functionality of core modules in your custom module you should be aware of few Drupal hooks. Let's see what are the essential hook you need to know.- hook_form_FORM_ID_alter()
- hook_form_alter()

Implementation of overriding core Validate and Submit functionality,
/* * Implementation of hook_form_FORM_ID_alter(). */ function MODULE_NAME_form_user_pass_alter(&$form, &$form_state, $form_id) { $array_key = array_search('user_pass_validate', $form['#validate']); if ($array_key === FALSE) array_unshift($form['#validate'], 'user_pass_validate'); else $form['#validate'][$array_key] = 'custom_user_pass_validate_function'; $array_key_sub = array_search('user_pass_submit', $form['#submit']); if ($array_key_sub === FALSE) array_unshift($form['#submit'], 'user_pass_submit'); else $form['#submit'][$array_key_sub] = 'custom_user_pass_submit_validate_function'; return $form; }In custom_user_pass_validate_function and custom_user_pass_submit_validate_function you can override the user_pass validate and submit functionality. This example is based on User forgot password module likewise you can implement the same for user_login & user_register_form modules. You can write your custom code for validation and submition with your custom functions like,
/* * Custom Validate function. */ function custom_user_pass_validate_function($form, &$form_state) { // validate the form here } /* * Custom Submit function. */ function custom_user_pass_submit_validate_function($form, &$form_state) { // custom database connection or some logic }These are all about writing custom validate and submit functionality for core modules in D7.
The post Custom Validate and Submit function for Login, Register & Forgot password modules in Drupal 7 ? appeared first on Mydons.