OK, here is what I've got so far:
I am wanting to run this function to validate that the online donation goes through with my online payment processor and if not to display a custom error message:
// Tie our validation function to the 'gform_validation' hook
add_filter('gform_validation_9', 'validate_donation');
function validate_donation($validation_result) {
// Make a call to donate.php validation function to validate the donation
$is_valid = process_payment();
// If the payment is valid we don't need to do anything
if($is_valid){
// Return the validation result
return $validation_result;
}
else{
// Fail the validation for the entire form
$validation_result['is_valid'] = false;
// Return the validation result
return $validation_result;
}
}
// This function runs the Donation script for eTapestry/SAGE
function process_payment() {
include("donate.php"); //this is the processing of the online donation
}
// This function changes the main validation message
add_filter("gform_validation_message_9", "change_message", 10, 2);
function change_message($message, $form){
global $donate_error;
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>';
}
If the payment info goes through then I would like to show the confirmation message assigned by the form notifications and if not then I want the custom message to be displayed via the function change_message function. I have used some of the code from your sample code found here (http://pastie.org/1769048) . What kind or response is the $is_valid variable looking for from the process_payment function? Is it looking for true/false? I currently am getting an error message no matter if the payment is valid or not.....its throwing an error either way. Any advise?
Posted 13 years ago on Monday September 12, 2011 |
Permalink