Guest User

Untitled

a guest
Jan 20th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1.  
  2. add_filter('gform_validation_9', 'validate_donation');
  3. function validate_donation($validation_result) {
  4.  
  5. //if form has already failed validation, don't process donation
  6. if(!$validation_result["is_valid"]){
  7. return $validation_result;
  8. }
  9.  
  10. // Make a call to process_payment function to process payment and check validity
  11. $is_valid = process_payment();
  12.  
  13. // If the payment is valid don't do anything, return $validation_result
  14. if($is_valid){
  15. // Return the validation result
  16. return $validation_result;
  17. }
  18. else{
  19. // Fail the validation for the entire form
  20. $validation_result['is_valid'] = false;
  21. // Return the validation result
  22. return $validation_result;
  23. }
  24. }
  25.  
  26. add_filter("gform_validation_message_9", "change_message", 10, 2);
  27. function change_message($message, $form){
  28. global $donate_error;
  29.  
  30. if(!empty($donate_error)){
  31. //only display custom validation message if there was an error with the donation processing
  32. return '<div id="donate_error">' . "An error occurred while processing your submission.<br/>Please modify your information based on the error below and try again.<br/><br/>" . '<span>' . "Error: {$donate_error}" . '</span>' . '</div>';
  33. }
  34. else{
  35. //display default message when a standard form validation error occurs.
  36. return $message;
  37. }
  38. }
Add Comment
Please, Sign In to add comment