Page 1 of 1

Help with date

Posted: Tue Nov 16, 2010 4:36 am
by crazzyapple
Hello:

I am having a problem with the date and I have been banging my head on it. And I do not know what to do.
I have an array that is:

Code: Select all

$form['job_posting_dob']= array(
'#type' => 'date', 
//'#date_format' => 'Y-m-d',

'#title' => t('Date of Birth'), 
'#description' => t('Chose your date of birth.'), 
'#default_value' => array('year' => $created['year'], 'month' => $created['mon'], 'day' => $created['mday']),  
Then when the send button is clicked it passes this code to write the date of birth to an email.

Code: Select all

.$form_state['values']['job_posting_dob'];
It works fine, but my problem is that, in the email it writes 'Array'. Not the chosen date that is picked from the date dropdown boxes.
I would like it to display day, month, year of what is chosen from the dropdown boxes.
Any help will be greatly appreciated.


Sincerely,
Ryan

Re: Help with date

Posted: Tue Nov 16, 2010 12:16 pm
by Jonah Bron
That's because $form_state['values']['job_posting_dob'] is an array. You want:

Code: Select all

$dob = $form_state['values']['job_posting_dob']['#default_value'];
echo $dob['year'] . '-' . $dob['month'] . '-' . $dob['day'];

Re: Help with date

Posted: Wed Nov 17, 2010 1:13 am
by crazzyapple
Hi:

Thank you, for taking the time to anwser my post Jonah Bron much appreciated.
I have inserted the code that you provided and it works, but when I click the send button the echo page displays '--' and to the email as well.

I have have textfields, textarea and radio buttons and they all send the correct information, but for this date it really has me perplexed. :banghead:

I have been changing and rechanging, but no such luck. And I am still not sure what the problem is.

Re: Help with date

Posted: Wed Nov 17, 2010 11:50 am
by Jonah Bron
Put this in, for debugging:

Code: Select all

echo '<pre>';
print_r($form_state);
echo '</pre>';
Post what you see here. That will tell us what's going on.

Re: Help with date

Posted: Wed Nov 17, 2010 11:26 pm
by crazzyapple
Thank you for taking the time to help me again, much love.

The problem was default_value:

Code: Select all

 $dob = $form_state['values']['job_posting_dob']['#default_value']; 
change to:

Code: Select all

$dob = $form_state['values']['job_posting_dob'];
I am not really sure why default_value is the problem because it was still getting stored, but to display it; I don't need it.


Cheers

Re: Help with date

Posted: Thu Nov 18, 2010 6:00 am
by crazzyapple
Trying to get the date to display correctly and do what I would like is really perplexing for me or I am just making it more complicated then it actually is.

I got some more issues with the date and the issues are tied in a vicious annoying cycle. I will try to explain it the best I can. And I apologize before hand if the post is long because I will include the results from: echo '<pre>'; print_r($form_state); echo '</pre>';

When I use my current date: job_posting_dob
It displays the date on the forum of 1 1 1900. I would like to place day month year in the boxes or blanks. I tried to place the code '#date_label_position' => 'within', but that does nothing. Is there away to put labels or a blank for day month year when using '#type' => 'date', ?

Here is where the vicious annoying cycle starts.

If I change my current date from '#type' => 'date', to '#type' => 'date_select',

I get the labels of year month day in the boxes when I use '#date_label_position' => 'within', However, on the echo page or the results sent to the email I get 2-2-2, which I think it is only displaying the first digit. When I use this:

Code: Select all

  $dob = $form_state['values']['job_posting_dob'];
.$dob['year'] . '-' . $dob['month'] . '-' . $dob['day'];[code]
I have made a new date array called job_posting_arrival:

Code: Select all

 $form['job_posting_arrival']= array(
'#type' => 'date_popup',
'#title' => t('Arrival Date'),  
'#date_label_position' => 'within',        
'#date_format' => 'y-m-d',
'#description' => t('Select your approximate arrival date.'),
);
When I use

Code: Select all

echo $arrival['year'] . '-' . $arrival['month'] . '-' . $arrival['day']
it also displays it as 2-2-2.

However, when I use

Code: Select all

echo .$form_state['values']['job_posting_arrival'];
it displays it correctly '2010-11-10 00:00:00'

Is there a way to remove the time or is that how it gets displayed either by using date_popup or date_select or am I stuck with the time to display?


Results:
Array
(
[storage] =>
[submitted] => 1
[values] => Array
(
[job_posting_reference] => JOB26
[job_posting_title] => Job Test
[job_posting_email] =>
[job_posting_coverletter] => efdgf
[job_posting_name] => fdgfd
[job_posting_tele] => 456546
[job_posting_dob] => 2008-02-28 00:00:00
[job_posting_arrival] => 2010-11-10 00:00:00
[job_posting_sex] => Male
[job_posting_nation] => Aus
[job_posting_resume] =>
[job_posting_picture] =>
[op] => Send
[job_posting_submit] => Send
[form_build_id] => form-efd698ba825d83c1b2b5beca146335b2
[form_token] => 97fb0fd0c5151efdabb8703fabc65cf9
[form_id] => job_posting_application_form
)

[clicked_button] => Array
(
[#type] => submit
[#value] => Send
[#post] => Array
(
[job_posting_coverletter] => efdgf
[job_posting_name] => fdgfd
[job_posting_tele] => 456546
[job_posting_dob] => Array
(
[year] => 2008
[hour] => 0
[minute] => 0
[second] => 0
[month] => 2
[day] => 28
)

[job_posting_arrival] => Array
(
[date] => 10-11-10
)

[job_posting_sex] => Male
[job_posting_nation] => Aus
[op] => Send
[form_build_id] => form-79194aada2ba0383e798021ad23223d1
[form_token] => 97fb0fd0c5151efdabb8703fabc65cf9
[form_id] => job_posting_application_form
)

[#programmed] =>
[#tree] =>
[#parents] => Array
(
[0] => job_posting_submit
)

[#array_parents] => Array
(
[0] => job_posting_submit
)

[#weight] => 0.013
[#processed] =>
[#description] =>
[#attributes] => Array
(
)

[#required] =>
[#input] => 1
[#name] => op
[#button_type] => submit
[#executes_submit_callback] => 1
[#process] => Array
(
[0] => form_expand_ahah
)

[#id] => edit-job-posting-submit
)

[process_input] => 1
[redirect] =>
)

Message body empty

Re: Help with date

Posted: Thu Nov 18, 2010 6:19 am
by fredators88

Re: Help with date

Posted: Fri Nov 19, 2010 9:05 pm
by crazzyapple
fredators88 wrote:You can look also over here.

http://www.sharedterminal.info/php-trai ... n-php.html
Cheers mate, let see if I cn get this going^^