displaying input field for date in a form

How do we display input field for date in a form.

for example, to display a textfield we use: <?php echo $form->textField($model,‘email’); ?>

and for password field we use: <?php echo $form->passwordField($model,‘confirm_password’); ?>

what do we use for the date input field in CActiveForm ?


Generally speaking the input types provided by CHtml (what CActiveForm inputs map to) are a one:one representations of HTML elements, HTML has no date input type for forms, you will need to create a solution from text inputs or other inputs, you could add javascript to make date selection more user friendly.

For example you could add:

  • Day

  • Month

  • Year

To your model and then collect those in seperate text inputs.

Or you can use datetime picker widget


<div class="row">

	<?php echo $form->labelEx($model,'start_date_time'); ?>

	<?php //echo $form->textField($model,'start_date_time'); ?>




		'model'=>$model, 				// Model object

		'attribute'=>'start_date_time', // Attribute name

		'mode'=>'datetime', 			// Use "time","date" or "datetime" (default)

		'options'=>array(), 			// jquery plugin options

		'htmlOptions'=>array('readonly'=>true) // HTML options



	<?php echo $form->error($model,'start_date_time'); ?>


Or, CJuiDatePicker, available in standar Yii distribution.