Skip to content

Instantly share code, notes, and snippets.

@mikeselander
Created February 28, 2014 03:46
Show Gist options
  • Save mikeselander/9264831 to your computer and use it in GitHub Desktop.
Save mikeselander/9264831 to your computer and use it in GitHub Desktop.
An example of gform_validation where we validate a field value based on a minimum value from a custom metabox
/**
* Custom validation so that a bid less than the minimum custom metabox is not allowed
*
* @since 0.1.0
*
*/
add_filter( "gform_field_validation_10_1", "min_bid_validation", 10, 4 );
function min_bid_validation( $result, $value, $form, $field ){
// Get the correct output from the form
$id = rgpost("input_3");
// Get the correct minimum bid out of a CMB & make sure it's a proper integer'
$min_bid = get_post_meta( $id, 'cmb_auction_min_bid', true );
$min_bid = intval(str_replace( ",", "", $min_bid ) );
// If the value from our field is less then the minimum bid, return false * give the user a reason.
if($result["is_valid"] && intval($value) < $min_bid){
$result["is_valid"] = false;
$result["message"] = "Please enter a value higher than the minimum bid (Minimum Bid on this auction is $$min_bid)";
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment