Name $_POST['LoginForm']

Hey guys,

After I create a new app,

there is following code in the SiteController, actionLogin method


$model = new LoginForm;


if(isset($_POST['LoginForm'])){

//

}

// display the login form

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



File ./views/site/login.php has following snippet code:




    

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(

  'id'=>'login-form',

  'enableClientValidation'=>true,

  'clientOptions'=>array(

    'validateOnSubmit'=>true,

  ),

)); ?>



I don’t see any assigment like


'post-name'=>'LoginForm'

in the ./views/site/login.php file which then will be read through


$_POST['LoginForm']

.

Where is the name $_POST[‘LoginForm’] coming from?

The [LoginForm] part has nothing to do with the form.

This comes from the name of the input element itself.

Explore the HTML code of the page and you will see that all names of inputs contain the name of the model too.

This is very useful, when working with multiple models and is done automatically.

Both GET and POST can be manipulated this way.

OK. I get it.

In the file ./views/site/login.php we have




<div class="row">

    <?php echo $form->labelEx($model,'username'); ?>

    <?php echo $form->textField($model,'username'); ?>

    <?php echo $form->error($model,'username'); ?>

  </div>



the $model class which is LoginForm determines the input name:




<input id="LoginForm_username" type="text" name="LoginForm[username]">



Thanks for your reply.

can i change the LoginForm in the name LoginForm[username]

plz help

yes you can, but should modify remainig code to use new id

StasuSS

could u plz explain, how?

change form id and fields id in login view, then change theese ids in sitecontroller’s login action

if i get you right