fieldname__validate Delegate Class Method
Return to Delegate class methods
Synopsis
Xataface allows you to add validation on any particular field in table by adding a fieldname__validate method to the table’s delegate class of the form:
function myfield__validate(&$record, $value, &$params){
if ( $value != 'Steve' ){
$params['message'] = 'Sorry you must enter "Steve"';
return false;
}
return true;
}
Parameters
- &$record : A Dataface_Record object encapsulating the record we are validating. Note that the values of this object correspond with the submitted values from the form, and not necessarily the actual values of the record in the database.
- $value : The value that is being inserted.
- &$params : An output array that can be used to pass back a message if validation fails. You would set this array’s ‘message’ parameter to be a message.
Returns
Returns a boolean value. True if the value is ok and false if validation failed.
See Also
- validators - For simple validation rules you can use the validator:VALIDATOR_NAME directive of the fields.ini file.
- Form Validation - Section on form validation in the Getting Started tutorial.
var disqus_identifier = ‘xataface.com/wiki/fieldname__validate’; (function() { var dsq = document.createElement(‘script’); dsq.type = ‘text/javascript’; dsq.async = true; dsq.src = ‘http://xataface.disqus.com/embed.js’; (document.getElementsByTagName(‘head’)[0] || document.getElementsByTagName(‘body’)[0]).appendChild(dsq); })(); blog comments powered by Disqus
//<![CDATA[ (function() { var links = document.getElementsByTagName(‘a’); var query = ‘?’; for(var i = 0; i < links.length; i++) { if(links[i].href.indexOf(‘#disqus_thread’) >= 0) { query += ‘url’ + i + ‘=’ + encodeURIComponent(links[i].href) + ‘&’; } } document.write(‘