0

i m working on a project in cakephp. i have a datepicker in my form:

<?php echo $this->Form->input('date1', array('div' => false,'type'=>'text','label'=>false,'class'=>'smallInput','tabindex'=>'4','id'=>'date1','style'=>'width:100px')); ?>

and here's the jquery code:

$(function() { $("#date1").datepicker({ minDate: 0 ,dateFormat: 'yy-mm-dd'}); });

i want to make sure the user selects a date which is already not present in the database. can i achieve this through a function in the model?

Gwenc37
  • 2,064
  • 7
  • 18
  • 22
TheIntern
  • 71
  • 9

1 Answers1

2

Use 'isUnique' :

   var $validate = array(
        'date1' => array(
        'unique' => array(
          'rule' => 'isUnique'

        )
    );

Date validation cake book

ColoO
  • 813
  • 5
  • 14
  • the "on create" part is usually not necessary. on update Cake knows to exclude the current record for it. – mark Apr 08 '14 at 11:53
  • and linking to the official documentation would also be helpful. – mark Apr 08 '14 at 12:04
  • thanks...what if i have to ensure unique records for a particular ID? – TheIntern Apr 08 '14 at 12:15
  • i don't understand your question :s. Can you deepen your explanation ? – ColoO Apr 08 '14 at 12:21
  • i am storing certain details along with the date, such as a user ID. so if user A selects a date, it can be available for user B, but user A cannot use it again. – TheIntern Apr 08 '14 at 12:23
  • maybe this [link](http://stackoverflow.com/questions/2461267/cakephp-isunique-for-2-fields/2464201#2464201) can help you. – ColoO Apr 08 '14 at 12:34