how to implement a date field in my forms using the form API. I actually wanted a date popup field. I have use this code

$form['dob'] = array(
  '#type' => 'date_popup',
  '#title' => t('DOB'),
  '#date_format' => 'Y-m-d',
  '#date_year_range' => '-100:+0',

but it does not work..

  • --> How did u manage to solve it? – alyssaeliyah Sep 24 '15 at 8:01

you would need to install the date module for date popup to work.

the following answer on stackoverflow has more details

How do I choose the "date_popup" widget for custom date field from code?

  • i have install the model and see this link but it still show me this error Undefined index: #id in theme_date_popup() (line 675 of all\modules\date\date_popup\date_popup.module). – Rasha Shareef Jan 18 '13 at 21:26
  • are you using the same format as aove? and where are placing it? – Mohammed Shameem Jan 19 '13 at 4:52
  • yes I have using the same format as above . in my custom module – Rasha Shareef Jan 19 '13 at 13:34
  • could you show be the full function that you have placed this in? – Mohammed Shameem Jan 19 '13 at 13:35
  • function _menu_example_menu_page {$form['dob'] = array( '#type' => 'date_popup', '#title' => t('DOB'), '#date_format' => 'Y-m-d', '#date_year_range' => '-100:+0', ); return $form; } do you have skype??? this my name (rasha.shareef) on skype could you add me :) – Rasha Shareef Jan 19 '13 at 14:00

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.