2

I'm trying to validate an input with CakePHP 2.3.8. When the input passes the validation it works fine. However, when it doesn't meet the validation requirements I get the following error

Warning (2): vsprintf(): Too few arguments [CORE/Cake/basics.php, line 619]

This displays at the top. Around the input where the message should be displayed, it's just a blank red outline, like the message wasn't passed.

Here's my validation

'sales_tax' => array(
        'valid' => array(
            'rule' => array('confirm_percentage'),
            'message' => 'Sales tax must be a percentage (Ex: 4.005%)'
        )
),

I also tried this without the 'valid' array and the error still persists. And the function

function confirm_percentage($value){
    if(preg_match('/^[0-9]/', $value['sales_tax'])){ //just checking if input starts with number for testing purposes
        return true; //no error
    }
}

1 Answer 1

3

Ultimately your validation rule message is being passed to vsprintf() (in __d()), and so it must be formatted to be sprintf compatible.

The problem is that you are passing an %, which is the conversion specifier identificator, and so vsprintf() expects you to pass additional arguments appropriately.

Long story short, escape the % with another %:

'message' => 'Sales tax must be a percentage (Ex: 4.005%%)'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.