Is there a way to restrict the expiration date to "not more than a year"?
I explain: I am building a site to which Teachers will give an access code to students for a year beginning on the first day of class and expiring exactly one year after. All classes do not start at the same date. I want to make sure teachers will not abuse the privilege or forget to give end date.

Thanks for any advice.

Comments

glekli’s picture

Have you tried using hook_form_alter? That way, you can modify the form or its fields, and add any custom logic.

You will most likely need to add a validator function, and do checks in there. Something like this:

// Implements hook_form_FORM_ID_alter().
function my_module_form_user_profile_form_alter(&$form, $form_state) {
   $form['#validate'][] = 'my_module_expiration_validate';
 }

// Validator callback
function my_module_expiration_validate($form, &$form_state) {
  // Check if you can accept the value in $form_state['values']['access_code_expiration']
  // If not, call form_set_error('access_code_expiration', $message);
}
hyperlinked’s picture

Issue summary: View changes

I've incorporated this into my patch against issue #2265509:
https://drupal.org/node/2265509

That patch adds functionality to allow you to set a default expiration interval from a module configuration page. Once set, the expiration will default to an interval into the future that you define.

hyperlinked’s picture

Assigned: Unassigned » hyperlinked

glekli’s picture

Status: Active » Fixed

This feature has been added in the latest release.

hyperlinked’s picture

Status: Fixed » Closed (fixed)

Verified. Closed.