--- validateage.module (original) +++ validateage.module (modified) @@ -116,23 +116,38 @@ validateage_birthday_update($account->uid, $edit['validateage_dob']['month'], $edit['validateage_dob']['day'], $edit['validateage_dob']['year']); break; case 'register': - $form = array(); - $form['validateage_dob'] = array( - '#type' => 'date', - '#title' => t('Date of Birth'), - '#description' => t('You must be at least @age to join @site', array('@age' => variable_get('validateage_age', 18), '@site' => variable_get('sitename', ''))), - ); - return $form; + $input_source_id = variable_get('validateage_field_id', '0'); + switch ($input_source_id) { + case '0': + $form = array(); + $form['validateage_dob'] = array( + '#type' => 'date', + '#title' => t('Date of Birth'), + '#description' => t('You must be at least @age to join @site', array('@age' => variable_get('validateage_age', 18), '@site' => variable_get('sitename', ''))), + ); + return $form; + break; + } break; case 'validate': - $minimum_age = variable_get('validateage_age', '18'); - $birthyear = $edit['validateage_dob']['year']; - $birthmonth = $edit['validateage_dob']['month']; - $birthdate = $edit['validateage_dob']['day']; - $birthday = implode("-", array($birthyear, $birthmonth, $birthdate)); + $input_source_id = variable_get('validateage_field_id', '0'); + switch ($input_source_id) { + case '0': + $birthyear = $edit['validateage_dob']['year']; + $birthmonth = $edit['validateage_dob']['month']; + $birthdate = $edit['validateage_dob']['day']; + $birthday = implode("-", array($birthyear, $birthmonth, $birthdate)); + break; + default: + $birthday = substr($edit['field_birthdate'][0]['value'], 0, 10); + } $age = _validateage_get_age($birthday); + $minimum_age = variable_get('validateage_age', '18'); if ($age < $minimum_age) { - form_set_error('registration', variable_get('validateage_fail_message', 'Sorry, we are unable to accept your registration at this time.')); + if($GLOBALS['user']->uid) + form_set_error('', t('Please contact the administrator to change your birthday.')); + else + form_set_error('', t(variable_get('validateage_fail_message', 'Sorry, we are unable to accept your registration at this time.'))); } elseif (_validateage_check_birthday($birthday)) { drupal_set_message(t('Happy Birthday!')); @@ -145,6 +160,25 @@ * This function defines the settings on the admin page */ function validateage_admin() { + // Get fields from the profile.module of the type 'date'. + $options = array(); + $result = db_query("SELECT fid, name FROM {profile_fields} WHERE type = 'date'"); + + while ($field = db_fetch_object($result)) { + $options[$field->fid] = $field->name; + } + + $options = array('independent input field') + $options; + + $form['validateage_field_id'] = array( + '#type' => 'select', + '#title' => t('Date of birth source'), + '#default_value' => variable_get('validateage_field_id', NULL), + '#description' => t("Select whether an independent input field shall be created or otherwise which profile field of type 'date' you want to use as date of birth. Note that the independent field is only shown to the user upon registration."), + '#options' => $options, + '#required' => TRUE, + ); + $form['validateage_age'] = array( '#type' => 'textfield', '#title' => t('Age'),