简体   繁体   中英

cakephp plugin data validation

I have a form on my homepage from an element in my Leads plugin. I have this in my Lead model:

public $validate = array(
    'last_name' => array(
        'notempty' => array(
            'rule' => array('notempty'),
            'message' => 'Your custom message here',
            'allowEmpty' => false,
        ),
    ),
    'phone' => array(
        'rocket' => array(
            'rule' => array('phone', null, 'us')
        ),
    ),
);

My app is validating correctly because it's not posting to my database unless I fill in required fields. The problem is that the because my url isn't /leads/add it's not showing my custom error messages on my fields when I submit the form.

I think it has something to do with the fact that I'm using an element. Anyone have any ideas or had trouble with this before?

The rule should be notEmpty instead of notempty. What is working right now is the allowEmpty set to false which makes sure the field is not empty using !empty($field) || is_numeric($field) !empty($field) || is_numeric($field) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM