Difference between #2 and #3 of
How to "masquerade" a non-required form element as 'required' one (in the view only)

Revision #3 has been created by Boaz on Sep 11, 2012, 1:32:59 PM with the memo:

indentation etc.
« previous (#2) next (#4) »

Changes

Title unchanged

How to "masquerade" a non-required form element as 'required' one (in the view only)

Category unchanged

How-tos

Yii version unchanged

Tags unchanged

required field, validation rules

Content changed

Problem ------------------ In a nutshell, the task at hand is to mark (or render) a model attribute in the typical "_form.php" view file with the 'required' red asterisk while this attribute is not marked as required in the model's rule() method.
If you're interested only in the solution, jump ahead to the 'solution' section below.
[...]
Consider the following use case:

 
- You have a model with two phone numbers attributes: _phone_ and _fax_. Phone is q required field while fax is not. Yet, if submitted, both should be validated as 'phone numbers', hence use a custom validator class, [PcSimplePhoneValidator](http://www.yiiframework.com/extension/pcsimplephonevalidator/)).
- So, you're rules() method will need to look like this:


```php
public function rules() {
[...]
5 1
6 followers
Viewed: 25 552 times
Version: 1.1
Category: How-tos
Written by: Boaz
Last updated by: mrun
Created on: Sep 11, 2012
Last updated: 7 years ago
Update Article

Revisions

View all history