The solution ended up being twofold:
- I had existing rule on the
phone_number
field that forced the value to be a US phone number. That rule also setallowEmpty
totrue
andrequired
tofalse
. I wanted to catch an empty value so I could display a particularly precise message. - I had to update the existing rule to flip the
allowEmpty
andrequired
values and also add a new rule with itslast
value set totrue
.
The final change, added in my controller action looks like this:
$this->Proposal->Requestor->validate = Set::merge(
$this->Proposal->Requestor->validate,
array(
'phone_number' => array(
'notempty' => array(
'rule' => 'notEmpty',
'message' => 'Please enter a phone number so can can contact you with any questions about the work.',
'allowEmpty' => false,
'required' => true,
'last' => true,
),
'usphone' => array(
'allowEmpty' => false,
'required' => true,
),
)
)
);
I can't remember whether I verified that the change to the existing usphone
rule was strictly necessary given the last
value of the new rule, but this combination is working fine.