Friday, November 22, 2013

RE: Best Practise - beforeValidate()

I know that.

I can simply set the validation to a-z and return the error to the user saying reason why error.

 

I am asking is it better to simply remove it in beforeValidate() then try to save it or simply skip beforeValidate() and send all the entered data direct to validation.

 

User enters $data['city'] = N3W Y0rk, now that’s not a real city so remove the 3 and the zero in before validate or just bypass it all together.

 

That’s all.

 

Thanks,

 

Dave

 

From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf Of Charles Blackwell
Sent: Friday, November 22, 2013 9:31 PM
To: cake-php@googlegroups.com
Subject: Re: Best Practise - beforeValidate()

 

You could use validation and create a custom method to validate to your specification.

http://book.cakephp.org/2.0/en/models/data-validation.html#custom-validation-rules

On Friday, 22 November 2013 18:43:34 UTC-5, advantage+ wrote:

What is the best way when saving data for example take city or first name field.

You want it to only be a-z and a space - or.(period)

 

Should you in beforeValidate do a preg_replace and remove anything that you do not want then save(attempt) it or simply use the validation rules to check and save / return false explaining why?

 

Just curious as to how people approach this and reasons for doing it either way.

 

Thanks,

Dave

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: