Hi! Is there a way to display multiple forms on one page?
Example:
in controllers action:
$modelOne = new ModelOne();
$modelTwo = new ModelTwo();
in view file:
$form = $this->beginWidget(‘CActiveForm’, array(
'id'=>'user-form',)
);
echo $form->textField($modelOne,‘model_one_attr’);
echo $form->textField($modelTwo,‘model_two_attr’);
this will allow U to have one form with multiple models, and also U will have sparated POST/GET:
$_POST[‘ModelOne’] and $_POST[‘ModelTwo’]
dragan.zivkovic, thanks!
Another question. What if i need to display second form on each page? I suppose it’s not a good idea to write to each action and view the same piece of code.
If I understood U right, U want to show each form on separate page?
Than U will have much cleaner code if U have one action for each model/page
I want the following:
-
on the left of the page there is a form that is shown constantly on every action of every controller. However this form has it’s own action and controller.
-
on the right of the page is content that depends of controller/action of current url.
How do i accomplish this? It’s a bad idea to insert the same code rendering the constant form to the left into each controller/action, right?
Yes, it’s bad idea to have same code in every controller, but I think that U can get what U want by creating ActionClass for your constant action. What U need to do is to exted CAction, do your logic there and just include this in every controller actions() method, you can even have a different name for same action in every controller, but you will be using and maintaining same code.
Please check this: