user_form_test.module 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. }
  57. /**
  58. * Implements hook_form_FORM_ID_alter().
  59. */
  60. function user_form_test_form_user_profile_form_alter(&$form, &$form_state) {
  61. if (variable_get('user_form_test_user_profile_form_rebuild', FALSE)) {
  62. $form['#submit'][] = 'user_form_test_user_account_submit';
  63. }
  64. }
  65. /**
  66. * Submit function for user_profile_form().
  67. */
  68. function user_form_test_user_account_submit($form, &$form_state) {
  69. // Rebuild the form instead of letting the process end. This allows us to
  70. // test for bugs that can be triggered in contributed modules.
  71. $form_state['rebuild'] = TRUE;
  72. }