Commit eb65187b authored by Steve Gerbino's avatar Steve Gerbino

Updating master branch

parent 6a079192
* @file
* Admin page callbacks for the Realname registration module.
* Admin page callbacks for the realname_registration module.
......@@ -14,15 +14,44 @@
function realname_registration_settings_form() {
$form = array();
$field_req = "
<li>".t('The field name is correct and represents an existing field')."</li>
<li>".t('The field is associated with the').' <em>'.t('user')."</em> ".t('entity')."</li>
<li>".t('The field is required and displays on the registration form')."</li>
$form['realname_registration_firstname_field'] = array(
'#type' => 'textfield',
'#title' => t('First name field'),
'#default_value' => variable_get('realname_registration_firstname_field'),
'#description' => t("The name of your first name field. Ensure that:").$field_req,
$form['realname_registration_lastname_field'] = array(
'#type' => 'textfield',
'#title' => t('Last name field'),
'#default_value' => variable_get('realname_registration_lastname_field'),
'#description' => t("The name of your last name field. Ensure that:").$field_req,
$form['realname_registration_format'] = array(
'#type' => 'radios',
'#title' => t('Username format'),
'#description' => t('Select the format in which Realname registration will create new usernames.'),
'#default_value' => variable_get('realname_registration_format', 'Firstname and lastname separated by a space'),
'#options' => array(t('Firstname and lastname separated by a space'), t('First initial and lastname')),
'#default_value' => variable_get('realname_registration_format', 0),
'#options' => array(t('First name and last name separated by a space (e.g., John Smith)'), t('First initial and last name (e.g., JSmith)')),
'#required' => TRUE,
$form['realname_registration_ucfirst'] = array(
'#type' => 'checkbox',
'#title' => t('Force the first letters of the first and last names to uppercase'),
'#default_value' => variable_get('realname_registration_ucfirst', 1),
'#description' => t("Ensures that the first letter of the users first name and first letter of the users last name are capitalized."),
$form['realname_registration_tolower'] = array(
'#type' => 'checkbox',
'#title' => t('Force lowercase'),
......@@ -30,5 +59,48 @@ function realname_registration_settings_form() {
'#description' => t("Usernames will be created using only lowercase characters."),
$form['realname_registration_use_validation'] = array(
'#type' => 'checkbox',
'#title' => t('Use Realname registration validation'),
'#default_value' => variable_get('realname_registration_use_validation', 1),
'#description' => t("Use regex to validate real names (/^[A-ZÀ-ÖØ-öø-ÿ]+$/i)"),
$form['#validate'][] = 'realname_registration_settings_validate';
return system_settings_form($form);
function realname_registration_settings_validate($form, &$form_state) {
// Retrieve the user instance and bundle using the field names provided.
$firstname_instance = field_info_instance('user', $form_state['values']['realname_registration_firstname_field'], 'user');
$lastname_instance = field_info_instance('user', $form_state['values']['realname_registration_lastname_field'], 'user');
$err_pretext = t('The field name').', <em>';
$err_req = '</em>, '.t("you've provided must be required.");
$err_unknown = '</em>, '.t("you've provided either does not exist or is not associated with the user entity and bundle.");
$err_textfield = '</em>, '.t('must use textfield widget.');
// We must check to see if the provided fields return a valid instance.
if(!isset($firstname_instance)) {
form_set_error('realname_registration_firstname_field', $err_pretext.$form_state['values']['realname_registration_firstname_field'].$err_unknown);
if(!isset($lastname_instance)) {
form_set_error('realname_registration_lastname_field', $err_pretext.$form_state['values']['realname_registration_lastname_field'].$err_unknown);
// The widget associated with the field the user has provided should be a text field.
if($firstname_instance['widget']['type'] != 'text_textfield') {
form_set_error('realname_registration_firstname_field', $err_pretext.$form_state['values']['realname_registration_firstname_field'].$err_textfield);
if($lastname_instance['widget']['type'] != 'text_textfield') {
form_set_error('realname_registration_lastname_field', $err_pretext.$form_state['values']['realname_registration_lastname_field'].$err_textfield);
// Because the field is used in creating usernames, it should be required.
if($firstname_instance['required'] != 1) {
form_set_error('realname_registration_firstname_field', $err_pretext.$form_state['values']['realname_registration_firstname_field'].$err_req);
if($lastname_instance['required'] != 1) {
form_set_error('realname_registration_lastname_field', $err_pretext.$form_state['values']['realname_registration_lastname_field'].$err_req);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment