Add Datepicker In Cform

Hi, All,

I want to add a datepicker (like CJuiDatePicker) into one element in CForm.

public function getForm() {

	$return=new CForm(array(





					'hint'=>'Date for network',





				"<script type=\"text/javascript\">


				jQuery(function($) {






My code is not working. I must be missing something but I don’t know.

Is anyone has same issue, and I want to know how you solve the issue.



Why not use CActiveForm ?

I don’t use often CForm but I think CActiveForm is more flexible

Thank you KonApaz,

I am design a form in one wizard step. So each wizard step is one class under Model, and in that class it calls getForm function, which return CForm to build the wizard page. Because each wizard step is one CFormModel. I don’t know how to change that. I am using WizardBehavior, I don’t know what is best way to handle that.

I designed another CActiveForm, but I don’t know how to insert it into wizard pages. Do you have any suggestions in this case?

Thank you for your time,



check something like that









Thank you KonApaz, you solution is correct.

It makes CForm very easier to use any widgets.


					'type'=>'zii.widgets.jui.CJuiDatePicker',  //this is widgets name

					'hint'=>'Initial status for the network',

					'attributes'=>array(  //put widgets options here






Very nice!

The type property can also be a class name or a path alias to the class. In this case, the input is generated using a widget of the specified class. Note, the widget must have a property called "model" which expects a model object, and a property called "attribute" which expects the name of a model attribute.

May not clear in above note, here is extend information.

Besides these built-in types, the type option can also take a widget class name or the path alias to it. The widget class must extend from CInputWidget or CJuiInputWidget. When rendering the input element, an instance of the specified widget class will be created and rendered. The widget will be configured using the specification as given for the input element.

thanks… :)