Yii Framework Forum: Form question - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Form question Rate Topic: -----

#1 User is offline   anotheryiinoob 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 04-February 16

Posted 12 February 2016 - 09:39 AM

I saw the following code in the tutorials and want to ask a few questions about it:

public function actionLogin()
{
    $model = new LoginForm;
    $form = new CForm('application.views.site.loginForm', $model);
    if($form->submitted('login') && $form->validate())
        $this->redirect(array('site/index'));
    else
        $this->render('login', array('form'=>$form));
}


1, What does the string 'login' refer to in the following: $form->submitted('login')
2, Why is that line of code required? Why not just $form->submitted() ?
3, What does the second parameter hold in the render function? Is it needed?

Many thanks.
0

#2 User is offline   Soul 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 38
  • Joined: 10-February 16
  • Location:Moscow, Russia

Posted 12 February 2016 - 10:58 AM

public function submitted($buttonName='submit',$loadData=true)
{
    $ret=$this->clicked($this->getUniqueId()) && $this->clicked($buttonName);
    if($ret && $loadData)
        $this->loadData();
    return $ret;
}


Method submitted() checks if form is submitted and assigns request data to model. Method validate() validates the models associated with this form.

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


Second parameter - data to be extracted into PHP variables and made available to the view script
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users