1
votes

I need to validate that a form input is numeric in CakePHP 1.3. However, the input is not a property of the model, so I don't think I should try to set the validation for it in the model. Instead, some calculations are done on that input and the results are used in the resulting model object. How can I validate this in the view/controller? That is, check that what the user input was numeric and show a validation error message if not before passing it through the calculations? Thanks!

2

2 Answers

2
votes

There's nothing wrong with defining model validation rules for non-existing / calculated fields, but you can also use the Validation class which might be cleaner. See 1 and 2.

1
votes

If you use jquery at least you don't have to do a full page reload to check. Especially if it's only for one value. Just another option, see if it helps!

if($('#Field').val() != "")
{
    if(!($.isNumeric($('#Field').val())) {
        alert('value must be numeric');
    }
}