My First Form

Hi everyone,

I am just starting to use Yii and so far I am very impressed. However since my programming skills are very basic I am looking for tutorials that describe step by step what I need to do.

The tutorial that I am looking for is a step by step tutorial on how to create my first form. There are several to be found but in my opinion all of them assume some level of knowledge that I lack.

If someone can be as kind to explain to me how I can start making my own forms in the simplest of steps like:

Step 1:

Create Myfirsform.php in /testdrive/models/

put this and that code to …

Step 2:

create myfirstform.php in /testdrive/controllers/

put this and that code

etc… etc…

for example at


  1. Creating a Simple Form

In the following, we show how to use the form builder to create a login form.

First, we write the login action code:


it does not specify in what folder I need to create a file. I am really trying to figure out what the basic steps are.

Thanks in advance,


Hi there ;) I`m also new in Yii but I will try to tell you what i know. I will use example from your link.

public function actionLogin()


    $model = new LoginForm;

    $form = new CForm('', $model);

    if($form->submitted('login') && $form->validate())



        $this->render('login', array('form'=>$form));


$form = (…) and path for it:

, next is validation and if condition:

(sry but I will not explain all of this cuz it’s kind of your job to get basics from PHP and moreover I don’t know everything.

So if u see an action, now you know where to find it.

Now please. Read you can really learn all the basics from guide. All my answers are from it ;)


If you really have problems with learning from docs try tutorials from youtube.

Hi Mentorq,

Thanks for the answer however it still doesn’t answer my original question. I am merely looking for a quick start guide on how to create a form.

Plus I think that you are mistaken in your answer. The first code snippet should go in /protected/models/LoginForm.php and not as you suggested in protected/views/site/loginForm.php

Anyway, in my opinion the documents are not very straightforward. It assumes too much knowledge of Yii from the start. It would really help if there is a very basic quick start explaining how to create an input form. Start with a Form Modal en then move to an Active Record type of form.

It`s not my suggestion. Read doc its just quote from it. Have you tried Blog tutorial ? Try to build basic app and then update it with more advance things. For me it was good way to start with Yii.

I found a tutorial that explains exactly what I was looking for.

Check out the link below:

Where to Start with Yii