Guest User

Untitled

a guest
Aug 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. <?php
  2. class SomeForm extends Form {
  3.  
  4. function validate(){
  5. if($this->validator){
  6. $errors = $this->validator->validate();
  7.  
  8. if($errors){
  9. if(Director::is_ajax() && $this->validator->getJavascriptValidationHandler() == 'prototype') {
  10. FormResponse::status_message(_t('Form.VALIDATIONFAILED', 'Validation failed'), 'bad');
  11. foreach($errors as $error) {
  12. FormResponse::add(sprintf(
  13. "validationError('%s', '%s', '%s');\n",
  14. Convert::raw2js($error['fieldName']),
  15. Convert::raw2js($error['message']),
  16. Convert::raw2js($error['messageType'])
  17. ));
  18. }
  19. } else {
  20. $data = $this->getData();
  21.  
  22. $formError = array();
  23. if ($formMessageType = $this->MessageType()) {
  24. $formError['message'] = $this->Message();
  25. $formError['messageType'] = $formMessageType;
  26. }
  27.  
  28. // Load errors into session and post back
  29. Session::set("FormInfo.{$this->FormName()}", array(
  30. 'errors' => $errors,
  31. 'data' => $data,
  32. 'formError' => $formError
  33. ));
  34.  
  35. }
  36. return false;
  37. }
  38. }
  39. return true;
  40. }
  41.  
  42. }
Add Comment
Please, Sign In to add comment