quick question: generator for form builder?

I am pretty sure there is a generator to create the configuration for a CFormModel but I cannot find it…

So after a lot of search, could you please share the link?

Thanks! :)

You can enable gii in the config file (protected/config/main.php)

After that you can use gii to generate a from based on a Model.

for example http://www.website.ext/index.php/gii works for me to start gii.

No I do not mean the default gii generator

I mean a generator for form builder. Something like that:




<?php

/**

	 * @return \CForm

	 */

	public function getForm($formClass='CForm') {

		$config = $this->getFormConfig();

		return new $formClass($config, $this);	//all subforms get as parent their model

	}

	

	public function getFormConfig() {

		$modelName = get_class();

		return array(

		    //'title' => '..............',

		    'showErrorSummary' => true,

		    /*'elements' => array(

				get_class() => $this->getFormElements(),

			),*/

			'elements' => $this->getFormElements(),

		    'buttons' => array(

		        'submit_'.lcfirst($modelName) => array(

					'type' => 'submit',

					'label' => 'Submit '.$modelName,

		        ),

		    ),/*

		    'attributes' => array(

		    	'enctype' => 'multipart/form-data', //ALWAYS REMEMBER TO DEFINE THIS WHEN HANDLING FILES

		    ),*/

		);

	}

	

	/**

	 * @return array configuration to be used inside the configuration of a complex (nested) CForm model

	 */

	public function getFormElements() {

		//d(array_values($this->allNames()));

		return array(

			'name' => array(

				'type' => 'zii.widgets.jui.CJuiAutoComplete',

				//'hint' => $this->hint,

				'attributes' => array(

					'id' => md5(microtime()*rand()),

					'source' => array_values( $this->retrieveColumn('name') ),

					'options' => array(   //options reference: http://jqueryui.com/demos/autocomplete/

						'minLength' => 1,

						'delay' => 200,

					),

				),

	        ),

	        'value' => array(

				'type' => 'text',

	        ),

			/*'activity_id' => array(

				'type' => 'hidden',

			),*/

		);

	}

?>



I would like to get the elements, the buttons etc. in the above array format.

Unless there is a certain gii configuration that I am missing … :confused:

Anyway thanks for the reply though :)

I don’t think there is, but it would be a great extension. I was just thinking of it this morning, and it shouldn’t be complicated to write. TIme-consuming, I am sure, but not complicated.