I have a select list in my registration form here. The user can select 3 options to register for the event. For now the user has the ability to choose an early bird registration. After the periode they shouldn't be able to select that option. Is there a way to disable that option?

I have the following options:

  3. LATE REGISTRATION Mar (1 - to conference)
  4. SPEAKERS REGISTRATION ( now to Apr 2)
  5. STUDENT REGISTRATION (breaks only)

After the 1nov I should be able to disable the early bird registration in the select list.


Disabling single options from select lists is currently not that easy in Drupal. There are some open issues regarding the topic and a couple of suggested patches, but so far neither made it into core:

That said, there is a tutorial on Exove which works around the issue, by implementing the THEME_select() hook to enable theming of individual select options using a #options_attributes key: Drupal 7 Form API select element option attributes

Using the code for your theme's template.php from the tutorial, you can disable options in your form using hook_form_FORM_ID_alter().

function hook_form_FORM_ID_alter() {
  $today = date("Y-m-d H:i:s");
  $date = "2016-11-01 00:00:00";

  if ($date > $today) {
    //replace 0 with the actual index for Early Bird
    $form['your_select_field']['#option_attributes'][0] = array('disabled' => 'true');

    //set the other fields based on dates here

There is also a module which seems to offer the same functionality as the theme code from the tutorial, but I have not yet tested it: Form Options Attributes. It seems to work in a similar fashion however and might be even a little easier to set up (since you don't need to write that theme function).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.