I have а custom module that will show some reports. It will have two textfields, so when a user clicks one of the fields "starting date" and "end date" a calendar will popup and will able to select the dates. After selecting the dates, it will show the table with the results.

I've been using "Date" module with content type/fields, but I've never done in a custom module.

If these are the two fields:


$content['starting_date'] = array(
     '#type' => 'textfield',
     '#title' => 'Starting date',

$content['end_date'] = array(
     '#type' => 'textfield',
     '#title' => 'End date',


How can I show the popup calendar when a user clicks on some of the textfields and show the results?

I'm using Drupal 7.

EDIT: I'm marking Clive's answer, but the date_popup works only on forms, not custom fields.

  • Why do you need a custom module for this? Isn't content type with fields doing the job?
    – m1n0
    Commented Feb 4, 2014 at 11:14
  • The page has a custom access callback, connects with a web service and all the results are gathering from there . Commented Feb 4, 2014 at 11:16

1 Answer 1


Assuming you have the date popup module installed and enabled:

$form['starting_date'] = array(
  '#type' => 'date_popup',
  '#title' => 'Starting date',
  '#date_format' => 'd/m/Y',
  '#default_value' => date('Y-m-d'),
  • I've just tried that. It doesn't show the popup. The date module and date_popup is already instaled. When I revert to "#type" => 'textfield' it's showing the textfield with no problems. Commented Feb 4, 2014 at 11:25
  • I just tried it too (copy and pasted) into a normal form, works perfectly for me
    – Clive
    Commented Feb 4, 2014 at 11:29
  • Ok, I've tried on a form too. Yes, it's working, but on my custom page callback that doesn't use form, I cannot make the date_popup appear. Commented Feb 4, 2014 at 11:32
  • The date popup is a form element, so it won't work outside of a form. If you don't want to use a form you'll need to implement a custom JS solution, the date module won't be able to help you unfortunately
    – Clive
    Commented Feb 4, 2014 at 11:37
  • +1 from me and I've edited my thread. So I guess I have to find how to implement custom JS for that. Too bad the date module wont help. Commented Feb 4, 2014 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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