adl46652
(Adl46652)
October 22, 2011, 5:53am
1
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 ?
l.jurgs
(L Jurgs)
October 22, 2011, 9:22am
2
Hi
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:
To your model and then collect those in seperate text inputs.
aruna470
(Aruna470)
October 22, 2011, 4:44pm
3
Or you can use datetime picker widget
http://www.yiiframework.com/extension/datetimepicker/
<div class="row">
<?php echo $form->labelEx($model,'start_date_time'); ?>
<?php //echo $form->textField($model,'start_date_time'); ?>
<?php
$this->widget('CJuiDateTimePicker',array(
'language'=>'',
'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'); ?>
</div>
putera
(Libputera)
October 22, 2011, 7:31pm
4
Or you can use datetime picker widget
http://www.yiiframework.com/extension/datetimepicker/
<div class="row">
<?php echo $form->labelEx($model,'start_date_time'); ?>
<?php //echo $form->textField($model,'start_date_time'); ?>
<?php
$this->widget('CJuiDateTimePicker',array(
'language'=>'',
'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'); ?>
</div>
Or, CJuiDatePicker , available in standar Yii distribution.