1

I can not figure this out for the life of me, I am trying to have doubt digit values for the day and month in my module using form api, I have tried this with the date api and still no luck,

my function looks like this

function set_dob_year_range($form_element) {
$form_element['year']['#options'] = drupal_map_assoc(range(1900, 2012));
return $form_element;
}

    $form['dob'] = array(
        '#type'  => 'date',
        '#title' => t('Date Of Birth'),
        '#default_value' => array(
            'month' => format_date(time(), 'custom', 'm'), 
            'day' => format_date(time(), 'custom', 'd'), 
            'year' => format_date(time(), 'custom', 'Y'),
        ),
        '#after_build' => array('set_dob_year_range'),
        '#required' => TRUE
    );

using in on the month should count the months values as 01 02 03 but instead its using 1 2 3, thing for the days it should be 01 02 03 instead its using 1 2 3.

Any help is greatly appreciated.

EDIT: The date formats are not passing through to the values for anyone that is confused. enter image description here

| improve this question | | | | |
  • Here are some date formats. @Epok has the right answer. – donutdan4114 Sep 18 '12 at 23:54
  • the date formats are not passing through to the values – – Jeremy Love Sep 19 '12 at 0:07
  • Can you take a screenshot of where the output is not what you are expecting? – donutdan4114 Sep 19 '12 at 0:12
  • im using firebug to go to the values to see what they are and the values are 1 2 3 ect instead of 01 02 03 and I did try m and d in the fields, it was actually the very 1st thing i tried – Jeremy Love Sep 19 '12 at 0:26
  • And you are sure the #default_value is working? If you type 'foo' for the month, you see 'foo'? – donutdan4114 Sep 19 '12 at 0:31
2

You should try, i think it will work

format_date(time(), 'custom', 'm');
format_date(time(), 'custom', 'd'); 
| improve this answer | | | | |
  • the date formats are not passing through to the values – Jeremy Love Sep 19 '12 at 0:06
0

Where do you see the output with the missing leading zeroes, are they going into the database like that? If not whatever is pulling the values is probably turning them into integers.

| improve this answer | | | | |
  • im using firebug to go to the values to see what they are and the values are 1 2 3 ect instead of 01 02 03 – Jeremy Love Sep 19 '12 at 0:27
0

Please try this and tell me changes,

function set_dob_year_range($form_element) {
$form_element['year']['#options'] = drupal_map_assoc(range(1900, 2012));
return $form_element;
}

    $form['dob'] = array(
        '#type'  => 'date_select',
        '#title' => t('Date Of Birth'),
        '#default_value' => array(
            'month' => str_pad(format_date(time(), 'custom', 'm'), 2, "0", STR_PAD_LEFT), 
            'day' => str_pad(format_date(time(), 'custom', 'd'), 2, "0", STR_PAD_LEFT), 
            'year' => format_date(time(), 'custom', 'Y'),
        ),
        '#after_build' => array('set_dob_year_range'),
        '#required' => TRUE
    );
| improve this answer | | | | |
  • It did not work, everything stayed the same =/ – Jeremy Love Sep 19 '12 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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