The thing is, if i create a field name 'Ticket/req_date' like what you had:
View Template:
<?php echo $form->input('Ticket/req_date',array('label'=>'Request Date','Size'=>'15','class'=>w8em format-m-d-y divider-dash highlight-days-12 no-transparency'));?>
The 'date picker' icon appears and it is workable. But it can not save the date value. So I view the html source, eventually it created an input text field with a name of 'data[Post][Ticket/req_date]', reflecting to my tables, I dont have any column name such asTicket/req_date in my 'post' table, I only have a column by the name 'date'. I think for you having such name will:
1. Make your 'date picker' icon appear, able to popup and even return the date value to the 'date' field once you clicked the pop up 'date picker'.
BUT
2. I think without any extra custom code, the add function will fail to automatically read, carry & insert the date value because your table dont have any column by the name of 'Ticket/req_date'. So better check on these.
ps: sorry I had left out desktop application development for ages bro. more into web these days.
Above all, my code is for using combo box like this: [day] [month] [year] [date_picker_ikon]
For such combo box, when calling the FD's date picker, the class name somehow must consist split-date in it. I tried to get it done by just using a text field, but failed. So i tried using using combo box instead & Alhamdulillah its running nicely.
In naming my input field, I stick in using the exact name as my table's column name.
Better start by checking whether you have copied all of the essential files in proper directory 1st to ensure your date picker icon to appear in your form.
After hours trying to fix the awesome date picker by FDhttp://www.frequency-decoder.com/demo/date-picker-v4/date-picker-v4.zip using this good tutorial by Marcel Manning, extending comments by Derek Herman, Rob Weaver, Paul Gardner, Ephraim Gariguez and all other good people here, finally I managed to get it working nicely.
Here it goes:
1. Create app_controller.php in /app/app_controller.php with these codes:
Controller Class:
<?php
class AppController extends Controller {
var $helpers = array('Javascript');//enables default.ctp using the Javascript $helpers
}
?>
2. In default.ctp found in /app/views/layouts/default.ctp, put these codes within the head tag:
3. I'm using a 'Post' controller with an 'add' action, so in my case, I created the view file of add.ctp in /app/views/posts/add.ctp, with these codes:
View Template:
<?php
//the cake's e() function is similiar to php's echo
e($form->create('Post'));//Create Form
//Create label for Date field named 'Date'
e($form->label('date', 'Date'));
//Create combo box for 'year' and call date picker's class.
//See in the class called got 'split-date'.
//Use this for splitting the day, month & year field.
e($form->year('date', '1900', date('Y') + 50, date('Y'), array('id' => 'FieldId', 'class' => 'show-weeks dateformat-d-ds-m-ds-Y statusformat-l-cc-sp-d-sp-F-sp-Y highlight-days-67 split-date opacity-90'), false));
//Create error massage feature, any error generated
//by $validation for 'date' in /app/models.post.php will show up here.
e($form->error('date', $session->flash()));
//Ends this form with a 'submit' button
e($form->end('Submit'));
?>
Make sure all 3 combo box consist of the same 'id' (in my case it is FieldId).
4. I'm using a 'Post' model, so in my case in post.php is in /app/models/post.php, put these codes:
Model Class:
<?php
//I'm just writing down the validation part
var $validate=array(
'date'=>array('rule'=>'date',
'required'=>true,
'message'=>'You must supply a valid date.')
);
?>
5. I'm using a 'Post' controller, so in my case in posts_controller.php is in /app/controllers/posts_controller.php, this is my 'add' function:
Controller Class:
<?php
function add() {
if (!empty($this->data)) {
$this->Post->create();
if ($this->Post->save($this->data)) {
$this->Session->setFlash('The Post has been saved',null,null,'top');
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash('The Post could not be saved. Please, try again.',null,null,'top');
}
}
}
?>
-By doing all above, I'm able to create date combo box separated by day, month and year.
-Beside my year combo box there is a calendar icon, when clicked, I'm able to browse specific date.
-I'm also able to validate my date entry (it will pop up date error message when wrong date was selected e.g: 31st Feb 2009 which dont exist).
-No problem in saving the date field into DB without performing before or after filter.
I am newbiew in Cakephp, I have view like this:
echo $form->input('RequestDate',array('size' => '15', 'class' => 'w8em format-m-d-y divider-dash highlight-days-12 no-transparency'));
but it display month with combo box month, date with combobox date, etc
It will success if I change my real field (requestDate) with dateOnly or some word such as mydate etc. As you can see the requesDate will never save date after the form saved.
The validation date is also not work and display "form can not be save" if I set your validation option in my model.
please tell me why. really thank
oktar
Hi Oktar, i got the same prob like u, eventually i solved it. 1st i show you the error file which shows 3 combo-box of month, day & year:
View Template:
<?php echo $form->input('Ticket/req_date',array('label'=>'Request Date','Size'=>'15','class'=>w8em format-m-d-y divider-dash highlight-days-12 no-transparency'));?>
The 'date picker' icon appears and it is workable. But it can not save the date value. So I view the html source, eventually it created an input text field with a name of 'data[Post][Ticket/req_date]', reflecting to my tables, I dont have any column name such asTicket/req_date in my 'post' table, I only have a column by the name 'date'. I think for you having such name will:1. Make your 'date picker' icon appear, able to popup and even return the date value to the 'date' field once you clicked the pop up 'date picker'.
BUT
2. I think without any extra custom code, the add function will fail to automatically read, carry & insert the date value because your table dont have any column by the name of 'Ticket/req_date'. So better check on these.
ps: sorry I had left out desktop application development for ages bro. more into web these days.
Above all, my code is for using combo box like this: [day] [month] [year] [date_picker_ikon]
For such combo box, when calling the FD's date picker, the class name somehow must consist split-date in it. I tried to get it done by just using a text field, but failed. So i tried using using combo box instead & Alhamdulillah its running nicely.
In naming my input field, I stick in using the exact name as my table's column name.
Better start by checking whether you have copied all of the essential files in proper directory 1st to ensure your date picker icon to appear in your form.
Here it goes:
1. Create app_controller.php in /app/app_controller.php with these codes:
Controller Class:
<?phpclass AppController extends Controller {
var $helpers = array('Javascript');//enables default.ctp using the Javascript $helpers
}
?>
2. In default.ctp found in /app/views/layouts/default.ctp, put these codes within the head tag:
View Template:
<head>
<?php echo $html->css('datepicker')."\n"; ?>
<?php echo $javascript->link('datepicker.js')."\n"; ?>
</head>
<body>
<div id="container">
<div id="content">
<div id="top"><strong><?php $session->flash('top');?></strong><br></div>
<?php echo $content_for_layout;?>
<div id="bottom"><strong><?php $session->flash('bottom');?></strong></div>
</div></div>
</body>
3. I'm using a 'Post' controller with an 'add' action, so in my case, I created the view file of add.ctp in /app/views/posts/add.ctp, with these codes:
View Template:
Make sure all 3 combo box consist of the same 'id' (in my case it is FieldId).<?php
//the cake's e() function is similiar to php's echo
e($form->create('Post'));//Create Form
//Create label for Date field named 'Date'
e($form->label('date', 'Date'));
//Create combo box for 'day'
e($form->day('date', date('d'), array('id' => 'FieldId-dd'), false)." - ");
//Create combo box for 'month'
e($form->month('date', date('m'), array('id' => 'FieldId-mm'), false)." - ");
//Create combo box for 'year' and call date picker's class.
//See in the class called got 'split-date'.
//Use this for splitting the day, month & year field.
e($form->year('date', '1900', date('Y') + 50, date('Y'), array('id' => 'FieldId', 'class' => 'show-weeks dateformat-d-ds-m-ds-Y statusformat-l-cc-sp-d-sp-F-sp-Y highlight-days-67 split-date opacity-90'), false));
//Create error massage feature, any error generated
//by $validation for 'date' in /app/models.post.php will show up here.
e($form->error('date', $session->flash()));
//Ends this form with a 'submit' button
e($form->end('Submit'));
?>
4. I'm using a 'Post' model, so in my case in post.php is in /app/models/post.php, put these codes:
Model Class:
<?php//I'm just writing down the validation part
var $validate=array(
'date'=>array('rule'=>'date',
'required'=>true,
'message'=>'You must supply a valid date.')
);
?>
5. I'm using a 'Post' controller, so in my case in posts_controller.php is in /app/controllers/posts_controller.php, this is my 'add' function:
Controller Class:
<?phpfunction add() {
if (!empty($this->data)) {
$this->Post->create();
if ($this->Post->save($this->data)) {
$this->Session->setFlash('The Post has been saved',null,null,'top');
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash('The Post could not be saved. Please, try again.',null,null,'top');
}
}
}
?>
-By doing all above, I'm able to create date combo box separated by day, month and year.
-Beside my year combo box there is a calendar icon, when clicked, I'm able to browse specific date.
-I'm also able to validate my date entry (it will pop up date error message when wrong date was selected e.g: 31st Feb 2009 which dont exist).
-No problem in saving the date field into DB without performing before or after filter.
Hope helps.
Hi Oktar, i got the same prob like u, eventually i solved it. 1st i show you the error file which shows 3 combo-box of month, day & year:
View: add.ctp
---
View Template:
e($form->input('date',array(
'label'=>'Date',
'size' => '15',
'class'=>'show-weeks dateformat-d-ds-m-ds-Y statusformat-l-cc-sp-d-sp-F-sp-Y highlight-days-67'
)));
Then i change it to this:
View Template:
e($form->input('Post/date',array(
'label'=>'Date',
'size' => '15',
'class'=>'show-weeks dateformat-d-ds-m-ds-Y statusformat-l-cc-sp-d-sp-F-sp-Y highlight-days-67'
)));
just change input name from 'date' to 'Post/date', then a text field and a date picker will appear