Forms Flashcards

(19 cards)

1
Q

What is ‘massive assignment’?

A

Massive assignment automatically assigns request data to a form model.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a ‘scenario’?

A

Scenarios are specific situations in which validation rules are applied. Model instances can be initialized with scenarios, like this:

$model = new LoginForm(‘scenarioName’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Any validation rules not assigned to a scenario will be applied to…

A

…all scenarios.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

For which attributes should you not add validation rules?

A

Those that do not originate from the end-user.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you declare an attribute to be safe, without a specific rule?

A

With the special ‘safe’ validation rule.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What two functions are used to retrieve validation errors?

A

CModel::getErrors and CModel::getError.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How can you display a label for each input field in a form?

A

Override the attributeLabels() method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

For the ‘username’ form attribute of the LoginForm model, what would you name the form input field?

A

LoginForm[username].

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does CHtml::activeLabel do?

A

It generates a label associated with the specific model attribute.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does CHtml:activeTextField do?

A

It generates a text input field for the specified model attribute, and changes its CSS class upon any input error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is CActiveForm?

A

A widget for facilitating form creation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is tabular input, in the context of Yii forms?

A

Input for multiple model instances, entered in one form. For example, a user registration form may contain both user and profile information.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the two most important properties of CForm?

A

CForm::elements and CForm::buttons.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does the __toString magic method of CForm do?

A

It calls render(), and then returns a string representation of the form object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the three types that a CForm::elements property can be?

A

Input element, static text string, or sub-form.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How can you add a decorational element to CForm::elements?

A

Just specify it as static text in the CForm::elements array.

17
Q

How can you specify a sub-form?

A

Configure the CForm::elements property with an element whose type is ‘form’.

18
Q

What’s the main benefit of using form builder?

A

Separation of logic and presentation.

19
Q

How do you create a stateful form?

A

Adjust the application config file as follows:

return array(‘activeForm’ => array(‘stateful’=>true));