Heres my code:
//Setup days
$data['days']['FALSE'] = 'Day';
//Setup months
$data['months'] = array('FALSE' => 'Month',
'1' => 'Jan',
'2' => 'Feb',
'3' => 'Mar',
'4' => 'Apr',
'5' => 'May',
'6' => 'Jun',
'7' => 'Jul',
'8' => 'Aug',
'9' => 'Sep',
'10' => 'Oct',
'11' => 'Nov',
'12' => 'Dec'
);
for($i=1;$i<=31;$i++){
$data['days'][$i] = $i;
}
//Setup years
$start_year = date("Y",mktime(0,0,0,date("m"),date("d"),date("Y")-100)); //Adjust 100 to however many year back you want
$data['years']['FALSE'] = 'Year';
for ($i=$start_year;$i<=date("Y");++$i) {
$data['years'][$i] = $i;
}
and here's my if statement:
if($this->form_validation->run()){
$month = $this->input->post('months');
$day = $this->input->post('days');
$year = $this->input->post('years');
$birthday = date("m-d-Y H:i:s",mktime(0,0,0,$month,$day,$year));
}
here's my corresponding code in my form in the view:
<p>
<label for="birthday">Birthday: </label>
<?php echo form_dropdown('days',$days). " " . form_dropdown('months',$months). " " . form_dropdown('years',$years); ?>
</p>
When I put the datepicker code directly in my controller the drop down on my form shows correctly. I wanted to be neat with my coding so decided to create a model and attempted to make calls from my controller but I get the undefined variable error a few times when my view tries to display the form.
I've done some research and wondering whether it's better to make my datepicker a helper "datepicker_helper.php" put the code in there and load it in my controller.
Is this the best way to do this?
If so can somebody give me a example of how I can do this? If there is another way can somebody show me please?
Thanks in advance.. I'm here to learn..