How To Create Dynamically Textbox


I need ta create dynamically some textBox in my view _form.

How can I do that ?

And in which action I must put the code ? On beforeRender maybe?



Can you be more specific about what you’re trying to achieve?

yes of course.

I have a exemple for what I would like to do in prado :

I think it would be more explicit as my explanation whith my bad english.

// retrieve as much row as it count in the table language

 $this->myLangues = ba_LangueRecord::finder()->findAllLangues();

        // Init the input texts for multilingual texts:

        foreach ($this->myLangues as $myLangue) {

            $myDiv = new TPanel();


            $myTextbox = new TTextBox();





            $myLabel = new TLabel();


            $myLabel->setText('* '.Prado::localize('nom').' ['.$myLangue->langue_nom.']');

            $myValidation = new TRequiredFieldValidator();






            $myDiv->Controls[] = $myLabel;

            $myDiv->Controls[] = $myTextbox;

            $myDiv->Controls[] = $myValidation;

            $this->nomPlaceHolder->Controls[] = $myDiv;


Is it more clear for you ?

at this point, I just did that :

  protected function beforeRender($view) 



        if ($view=="update" || $view=="create"){


             $this->myLangues = BaLangue::model()->find();


           foreach ($this->myLangues as $myLangue) {

            $myTextbox = new CFormInputElement(array('size'=>45,'maxlength'=>45,'type'=>'textfield'),$form); 



but it doesn’t work

You need findAll() rather than find() if you’re looking to return all of the records in the table.

That aside, I’m still not sure what you’re trying to achieve with the code. You might want to go through the Yii guide, especially the section on forms.