Mark Royko + Associates

773-779-6301

Chicago Web Site Design

Our design process considers every aspect of your site, from easy navigation, to search engine optimization. Whether it's clean or ornamental, your site will look great and function perfectly.

Production

From online magazines to ecommerce, we can build you a site that is rock solid, easy to use and extremely affordable.

Web Site Maintenance and Service

At MR+A, we've got your back: After you're site is complete, we'll be there for service and support whenever you need us.

Topic “Drupal Module Development”

Formatting the Date Popup

Once in awhile, you'll work on a Drupal problem that takes forever to figure out, then find the answer hidden in plain sight. (Sitting right there. Laughing at you.) Oh look: Here's one now. I was using the date popup widget in a module form field and wanted the fancy calendar pop up, but just needed the month, day and year, not the time, etc.

Of course, I was too sophisticated and lazy to look it up, so I struggled with it for way too long. To save anyone else some time, here's how it's done: Explicitly set the date format in PHP syntax, then assign that within the element array. Couldn't. Be. Simpler. (Take a look at http://drupal.org/node/292667 It's right there in the comments in the sample code.):

  // Provide a format using regular PHP format parts (see documentation on php.net).
  // If you're using a date_select, the format will control the order of the date parts in the selector,
  // rearrange them any way you like. Parts left out of the format will not be displayed to the user.
  $format = 'Y-m-d H:i';
 
  $form['date2'] = array(
     '#type' => 'date_select',
     '#title' => 'select a date',
     '#default_value' => $date,
    '#date_format' => $format
 
 ... (etc)

Read that again: Parts left out of the format will not be displayed to the user.

So, basically, all you have to do is remember to set the format. In my case, the format would just read, 'm-d-Y'. That drops the time format field.

Syndicate content

Tune In. Sign On.

Sign up for the MR+A newsletter: Quarterly information on web development, design and optimization