How to add a date popup calendar onto a custom form Submitted by  Oliver Davies   on 23 May, 2012 - 10:42
First, I need to download the  Date   module, and make my module dependent on date_popup by adding the following line into my module's .info file.
dependencies[] = date_popup
 
                                Within my form builder function:
$form['date'] = array(
  '#title' => t('Arrival date'),
  '#type' => 'date_popup', // Provided by the date_popup module
  '#date_format' => 'j F Y', // Uses the PHP date() format - http://php.net/manual/en/function.date.php
  '#date_year_range' => '0:+2', // Limits the year range to the next two upcoming years
  '#required' => TRUE,
  '#default_value' => date('Y-m-d', time()), // Default value must be in 'Y-m-d' format.
);
来自  http://www.oliverdavies.co.uk/blog/add-date-popup-calendar-custom-form  
                            下面红色是就是日期的各种 type 类型  function date_widget_info() {    $info  =  array (      'date_select '  =>  array (        'label'  =>  t( 'Select List' ),        'field types'  =>  array ( 'date' ,  'datestamp' ,  'datetime' ),        'multiple values'  =>  CONTENT_HANDLE_CORE ,        'callbacks'  =>  array (          'default value'  =>  CONTENT_CALLBACK_CUSTOM ,         ),     ),      'date_select_repeat '  =>  array (        'label'  =>  t( 'Select List with Repeat options' ),        'field types'  =>  array ( 'date' ,  'datestamp' ,  'datetime' ),        'multiple values'  =>  CONTENT_HANDLE_MODULE ,        'callbacks'  =>  array (          'default value'  =>  CONTENT_CALLBACK_CUSTOM ,         ),     ),      'date_text '  =>  array (        'label'  =>  t( 'Text Field with custom input format' ),        'field types'  =>  array ( 'date' ,  'datestamp' ,  'datetime' ),        'multiple values'  =>  CONTENT_HANDLE_CORE ,        'callbacks'  =>  array (          'default value'  =>  CONTENT_CALLBACK_CUSTOM ,         ),       ),      'date_text_repeat '  =>  array (        'label'  =>  t( 'Text Field with Repeat options' ),        'field types'  =>  array ( 'date' ,  'datestamp' ,  'datetime' ),        'multiple values'  =>  CONTENT_HANDLE_MODULE ,        'callbacks'  =>  array (          'default value'  =>  CONTENT_CALLBACK_CUSTOM ,         ),       ),     );    if  (module_exists( 'date_popup' )) {      $info [ 'date_popup ' ] =  array (        'label'  =>  t( 'Text Field with Date Pop-up calendar' ),        'field types'  =>  array ( 'date' ,  'datestamp' ,  'datetime' ),        'multiple values'  =>  CONTENT_HANDLE_CORE ,        'callbacks'  =>  array (          'default value'  =>  CONTENT_CALLBACK_CUSTOM ,         ),     );      $info [ 'date_popup_repeat ' ] =  array (        'label'  =>  t( 'Text Field with Date Pop-up and Repeat options' ),        'field types'  =>  array ( 'date' ,  'datestamp' ,  'datetime' ),        'multiple values'  =>  CONTENT_HANDLE_MODULE ,        'callbacks'  =>  array (          'default value'  =>  CONTENT_CALLBACK_CUSTOM ,         ),     );   }    if  (!module_exists( 'date_repeat' )) {      unset ( $info [ 'date_select_repeat' ]);      unset ( $info [ 'date_text_repeat' ]);      if  ( isset ( $info [ 'date_popup_repeat' ])) {        unset ( $info [ 'date_popup_repeat' ]);     }   }    return  $info ; } 
date_select By 
jrs69  on 
13 Sep 2010 at 20:26 UTC Hi I am trying to change a date field on a form so that only the month and year are options for the user.
As of now, my code looks like this:
$format = 'm-Y'; $date = '01-2010'; $form['wpDate'] = array( '#type' => 'date_select', '#title' => t('Date of Latest Revision'), '#required' => TRUE, '#weight' => 8, '#default_value' => $date, '#date_format' => $format, );
This is based on the content of this website.... http://drupal.org/node/292667 
                                                    
however, this field just won't appear on my form. every time i change the #type from "date" to "date_select" the field vanishes.
Any help?
  
Comments
_
Do you have the Date API module installed and enabled?
Log in or register to post comments
Thanks, the Date API module
Thanks, the Date API module was exactly what I was missing.
Log in or register to post comments
来自 https://www.drupal.org/forum/support/module-development-and-code-questions/2010-09-13/date_select