Hi, I have an order form and I want to have a validation for coupons. They are made as CPT called "kupon" and have title as description, coupon code, date when the coupon starts to be valid and date of expiration. In order form is a field "kupon" for placing the code. Can you show me, how to validate the coupon code using the button and display the result by based on the validation of code and dates? Thank you.
<div class="form-group">
[cred_field field='kupon' post='objednavka' value='' urlparam='' class='form-control col-lg-8' output='bootstrap']
<input class="col-lg-4" type="button" value="Uplatnit">
</div>
Hi, custom validation can be added using the cred_form_validate API. Here's the general format:
add_filter('cred_form_validate','custom_kupon_validation',10,2);
function custom_kupon_validation($error_fields, $form_data)
{
//field data are field values and errors
list($fields,$errors)=$error_fields;
//uncomment this if you want to print the field values
//print_r($fields);
//validate if specific form
if ($form_data['id']==12345)
{
if( $fields['wpcf-kupon']['value'] = 0 ) {
$errors['wpcf-kupon']='Invalid kupon!';
}
}
//return result
return array($fields,$errors);
}
Change 12345 to the numeric ID of your CRED form, and modify the conditional validation code as needed. If you need more specific information about the conditionals, let me know.