string espected but array given in custom pop_date field #default_value Possible Duplicate:
  Date popup form field doesn’t show the default value correctly  




I'm trying to set a default value for my custom date_popup field. To be precise I'm trying tho set the field to the first day of the current month. But if I can populate the field without errors I can figure out the rest.

At first I was trying to input a string value:

#default_value = '1/1/2012'

This results in no errors but also the field will remain empty.

I've looked trough some issues including this one and noticed that I had to use a date() as value.
But this also results in an empty field using the the following code:

'#default_value' =&gt; date('d/m/Y'),


Which I think should give todays date?

Finally I used the following code:

'#default_value' =&gt; array('day' =&gt; 1, 'month' =&gt; date('m'), 'year' =&gt; date('Y')),


which populates the field but gives me:


  Warning: strlen() expects parameter 1 to be string, array given in
  date_default_date() (line 114 of
  /home/quickstart/websites/nieuwesite/sites/all/modules/date/date_api/date_api_elements.inc).


Of course I'm trying to build this field in hook_form(). for reference here is my whole field:

$form['click_stats_date_start'] = array(
'#type' =&gt; 'date_popup',
'#title' =&gt; t('Start date'),
'#label_display' =&gt; '',
'#date_format' =&gt; 'd/m/Y',
'#date_year_range' =&gt; '-1:+0',
'#date_label_position' =&gt; 'hidden',
'#default_value' =&gt; array('day' =&gt; 1, 'month' =&gt; date('m'), 'year' =&gt; date('Y')),
'#size' =&gt; 20,
'#required' =&gt; TRUE,
);


So my question is how do I populate the date_popup field on the first load without errors?
You are getting the "expects parameter 1 to be string" error because the only value the date popup form element accepts as default value is a string with the format described in date_popup_element_info().


  Set the #type to date_popup and fill the element #default_value with a date adjusted to the proper local timezone in datetime format (YYYY-MM-DD HH:MM:SS).


The code you should use is the following one.

$form['click_stats_date_start'] = array(
  '#type' =&gt; 'date_popup',
  '#title' =&gt; t('Start date'),
  '#label_display' =&gt; '',
  '#date_format' =&gt; 'd/m/Y',
  '#date_year_range' =&gt; '-1:+0',
  '#date_label_position' =&gt; 'hidden',
  '#default_value' =&gt; date('Y-m-d'),
  '#size' =&gt; 20,
  '#required' =&gt; TRUE,
);


If you need to visualize a specific value as default value, then the code should be the following one. (Replace $saved_timestamp with the value you need to show.)

$form['click_stats_date_start'] = array(
  '#type' =&gt; 'date_popup',
  '#title' =&gt; t('Start date'),
  '#label_display' =&gt; '',
  '#date_format' =&gt; 'd/m/Y',
  '#date_year_range' =&gt; '-1:+0',
  '#date_label_position' =&gt; 'hidden',
  '#default_value' =&gt; date('Y-m-d', $saved_timestamp),
  '#size' =&gt; 20,
  '#required' =&gt; TRUE,
);