Forms Flashcards
(19 cards)
What is ‘massive assignment’?
Massive assignment automatically assigns request data to a form model.
What is a ‘scenario’?
Scenarios are specific situations in which validation rules are applied. Model instances can be initialized with scenarios, like this:
$model = new LoginForm(‘scenarioName’);
Any validation rules not assigned to a scenario will be applied to…
…all scenarios.
For which attributes should you not add validation rules?
Those that do not originate from the end-user.
How do you declare an attribute to be safe, without a specific rule?
With the special ‘safe’ validation rule.
What two functions are used to retrieve validation errors?
CModel::getErrors and CModel::getError.
How can you display a label for each input field in a form?
Override the attributeLabels() method.
For the ‘username’ form attribute of the LoginForm model, what would you name the form input field?
LoginForm[username].
What does CHtml::activeLabel do?
It generates a label associated with the specific model attribute.
What does CHtml:activeTextField do?
It generates a text input field for the specified model attribute, and changes its CSS class upon any input error.
What is CActiveForm?
A widget for facilitating form creation.
What is tabular input, in the context of Yii forms?
Input for multiple model instances, entered in one form. For example, a user registration form may contain both user and profile information.
What are the two most important properties of CForm?
CForm::elements and CForm::buttons.
What does the __toString magic method of CForm do?
It calls render(), and then returns a string representation of the form object.
What are the three types that a CForm::elements property can be?
Input element, static text string, or sub-form.
How can you add a decorational element to CForm::elements?
Just specify it as static text in the CForm::elements array.
How can you specify a sub-form?
Configure the CForm::elements property with an element whose type is ‘form’.
What’s the main benefit of using form builder?
Separation of logic and presentation.
How do you create a stateful form?
Adjust the application config file as follows:
return array(‘activeForm’ => array(‘stateful’=>true));