date picker

Hi,

I have used the CJuiDatepicker and it is working fine. I have used it in the date of birth field in my form. I want to validate or accept only those users whose age is above 18.

Any ideas how to go about it?

Thanks,

set the year from date(‘Y’)-100 (for example) to date(‘y’)-18

Thanks for your reply,

Can u be more specific about how to write it in CJuiDatepicker.

The year should change accordingly so that only users who are 18 and above can register.

Thanks,

I have next one code for DatePicker


					<?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(

						'attribute'=>'birthday','model'=>$model, 'options'=>array(

							'showOn'=>'button',

							'showButtonPanel'=>true,

							'yearRange'=>'1910:1995',

							'defaultDate'=>'-41y',

							'changeMonth'=>true,

							'changeYear'=>true,

							'buttonText'=>'',

							

						),

					));?>



Hi,

I want to validate or accept only those users whose age is above 18. In 2011 the users whose age is 18 have their date of birth as 1993 and next year the users whose age will be 18 will have their date of birth as 1994 and so on. I want the calendar to show the years accordingly ie. if the calendar starts from say 1970 to 1993 in 2011 then the next year the year range should be 1970 to 1994 and so on. It should change dynamically with each passing year.

Thanks,

you can calculate a max year and insert it into ‘yearRange’=>‘1970:’.date(“Y”)-18

then you need to work with validators in the same way of calculating a max year of birth.

Hi,

Thanks for the reply

Here is my code

<div class="row">

	&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'dob'); ?&gt;


    &lt;?php

$yearNow = date("Y");

$yearFrom = $yearNow - 100;

$yearTo = $yearNow - 18;

$arrYears = array();

	 foreach (range(&#036;yearFrom, &#036;yearTo) as &#036;number) {


	 &#036;arrYears[&#036;number] = &#036;number; 


	 }

$arrYears = array_reverse($arrYears, true);

	 &#036;this-&gt;widget('zii.widgets.jui.CJuiDatePicker', array(

‘model’=>$model,

‘attribute’=>‘dob’,

‘options’=>array(

//‘showAnim’=>‘slideDown’, // ‘show’ (the default), ‘slideDown’, ‘fadeIn’, ‘fold’

‘showOn’=>‘focus’, // ‘focus’, ‘button’, ‘both’

‘buttonImage’=>Yii::app()->request->baseUrl.’/images/calendar.png’,

‘buttonImageOnly’=>true,

‘htmlOptions’=>array(‘readonly’=>“readonly”,),

‘changeMonth’=>true,

‘changeYear’=>true,

‘yearRange’=>‘1970:$arrYears’,

‘mode’=>‘date’,

‘dateFormat’=>‘yy-mm-dd’,

‘htmlOptions’=>array(

‘size’=>43,)

)));?>

<?php echo $form->dropDownList($model,‘dob’,$arrYears);?>

</div>

When you run this code you will get a datepicker and a dropdown besides it. The second drop down contains the appropriate years. I want the year drop down of the datepicker like the second dropdown ie the years start from 1911 to 1993 without explicitly specifying it.

Any ideas plz?

Thanks,

Any ideas?

Thanks,

Hi,

Dob is a required field in my form.I need to accept only those users who are above 18. Can i validate it in the model using some range validator or compare operator. If so then how? Does someone has a better idea?

Thanks,