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' => date('d/m/Y'),
Which I think should give todays date?
Finally I used the following code:
'#default_value' => array('day' => 1, 'month' => date('m'), 'year' => 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' => 'date_popup', '#title' => t('Start date'), '#label_display' => '', '#date_format' => 'd/m/Y', '#date_year_range' => '-1:+0', '#date_label_position' => 'hidden', '#default_value' => array('day' => 1, 'month' => date('m'), 'year' => date('Y')), '#size' => 20, '#required' => TRUE, );
So my question is how do I populate the date_popup field on the first load without errors?