form = $form;
}
function validate(){
$this->errors = null;
$this->php($this->form->getData());
return $this->errors;
}
/**
* Callback to register an error on a field (Called from implementations of {@link FormField::validate})
*
* @param $fieldName name of the field
* @param $message error message to display
* @param $messageType optional parameter, gets loaded into the HTML class attribute in the rendered output
*/
function validationError($fieldName,$message,$messageType=''){
$this->errors[] = array(
'fieldName' => $fieldName,
'message' => $message,
'messageType' => $messageType,
);
}
function showError(){
debug::show($this->errors);
}
function getCombinedError(){
if($this->errors) {
foreach($this->errors as $error){
$ret['message'] .= $error['message']."
";
$ret['messageType'] .= $error['messageType']."
";
}
return $ret;
}
}
function getError(){
return $this->errors;
}
function requireField($fieldName, $data) {
if(!$data[$fieldName]) $this->validationError($fieldName, "$fieldName is required", "required");
}
function includeJavascriptValidation() {
Requirements::javascript("jsparty/prototype.js");
Requirements::javascript("jsparty/behaviour.js");
Requirements::javascript("jsparty/prototype_improvements.js");
Requirements::javascript("sapphire/javascript/Validator.js");
$code = $this->javascript();
$formID = $this->form->FormName();
$js = <<form) $this->form->jsValidationIncluded = true;
}
/**
* Returns true if the named field is "required".
* Used by FormField to return a value for FormField::Required(), to do things like show *s on the form template.
* By default, it always returns false.
*/
function fieldIsRequired($fieldName) {
return false;
}
abstract function javascript();
abstract function php($data);
}
?>