home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (user_form_test.module)

This example Drupal source code file (user_form_test.module) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

account, array, description, field, form, function, items, password, php, return, title, type, user, value

The user_form_test.module Drupal example source code

<?php
// $Id: user_form_test.module,v 1.1 2010/12/11 06:22:33 webchick Exp $

/**
 * @file
 * Dummy module implementing a form to test user password validation
 */

/**
 * Implements hook_menu().
 *
 * Sets up a form that allows a user to validate password.
 */
function user_form_test_menu() {
  $items = array();
  $items['user_form_test_current_password/%user'] = array(
    'title' => 'User form test for current password validation',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('user_form_test_current_password',1),
    'access arguments' => array('administer users'),
    'type' => MENU_SUGGESTED_ITEM,
  );
  return $items;
}

/**
 * A test form for user_validate_current_pass().
 */
function user_form_test_current_password($form, &$form_state, $account) {
  $account->user_form_test_field = '';
  $form['#user'] = $account;

  $form['user_form_test_field'] = array(
    '#type' => 'textfield',
    '#title' => t('Test field'),
    '#description' => t('A field that would require a correct password to change.'),
    '#required' => TRUE,
  );
  
  $form['current_pass'] = array(
    '#type' => 'password',
    '#title' => t('Current password'),
    '#size' => 25,
    '#description' => t('Enter your current password'),
  );

  $form['current_pass_required_values'] = array(
    '#type' => 'value',
    '#value' => array('user_form_test_field' => t('Test field')),
  );

  $form['#validate'][] = 'user_validate_current_pass';
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Test'),
  );
  return $form;
}

/**
 * Submit function for the test form for user_validate_current_pass().
 */
function user_form_test_current_password_submit($form, &$form_state) {
  drupal_set_message(t('The password has been validated and the form submitted successfully.'));
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal user_form_test.module source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.