user_form_test.module

You are here

Dummy module implementing a form to test user password validation

Functions

File

modules/user/tests/user_form_test.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * Dummy module implementing a form to test user password validation
  5. */
  6. /**
  7. * Implements hook_menu().
  8. *
  9. * Sets up a form that allows a user to validate password.
  10. */
  11. function user_form_test_menu() {
  12. $items = array();
  13. $items['user_form_test_current_password/%user'] = array(
  14. 'title' => 'User form test for current password validation',
  15. 'page callback' => 'drupal_get_form',
  16. 'page arguments' => array('user_form_test_current_password',1),
  17. 'access arguments' => array('administer users'),
  18. 'type' => MENU_SUGGESTED_ITEM,
  19. );
  20. return $items;
  21. }
  22. /**
  23. * A test form for user_validate_current_pass().
  24. */
  25. function user_form_test_current_password($form, &$form_state, $account) {
  26. $account->user_form_test_field = '';
  27. $form['#user'] = $account;
  28. $form['user_form_test_field'] = array(
  29. '#type' => 'textfield',
  30. '#title' => t('Test field'),
  31. '#description' => t('A field that would require a correct password to change.'),
  32. '#required' => TRUE,
  33. );
  34. $form['current_pass'] = array(
  35. '#type' => 'password',
  36. '#title' => t('Current password'),
  37. '#size' => 25,
  38. '#description' => t('Enter your current password'),
  39. );
  40. $form['current_pass_required_values'] = array(
  41. '#type' => 'value',
  42. '#value' => array('user_form_test_field' => t('Test field')),
  43. );
  44. $form['#validate'][] = 'user_validate_current_pass';
  45. $form['submit'] = array(
  46. '#type' => 'submit',
  47. '#value' => t('Test'),
  48. );
  49. return $form;
  50. }
  51. /**
  52. * Submit function for the test form for user_validate_current_pass().
  53. */
  54. function user_form_test_current_password_submit($form, &$form_state) {
  55. drupal_set_message(t('The password has been validated and the form submitted successfully.'));
  56. }