In D7 I'm using date popup form element:

$form['sidebar']['reg_date']['from'] = array(
    '#type' => 'date_popup',
    '#title' => t('From:'),

When user click the textfield a popup calendar will appear, but user also can type the date into the textfield. But he can write something invalid like '44444' and this value will be returned in form state values without any form error. It would be useful if this module had an option for restricting typing date by keyboard. Is there any option for this?

I also have one side question: Is there any option to return unix timestamp value instead of formatted date in form state values? In my case it returns date in format '29.5.2016'.

1 Answer 1


You can use ['#attributes'] = array('readonly' => 'readonly');


    $date_format = 'd/m/Y H:i';
    $form['campaign_popup'] = array(
          '#type' => 'date_popup',
          '#date_format' => $date_format,
          '#default_value' => variable_get('campaign_popup'),
          '#title' => t(' Campaign Start Date.'),
          '#date_label_position' => 'within',
          '#date_year_range' => '0:+3',
          '#datepicker_options' => array('minDate' => 0),
          '#attributes' => array('readonly' => 'readonly'),
  • Updated my answer with $date_format. And please consider accepting the answer if you got the solution. Thanks
    – NTT
    Aug 19, 2016 at 11:50
  • readonly works well, but I need timestamp in form state values, this will return date in your format 'd/m/Y H:i'
    – Incredible
    Aug 19, 2016 at 11:52
  • You need to use strtotime($form_state['values']['campaign_popup']);
    – NTT
    Aug 19, 2016 at 11:54

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.