Hi there. I'd love to have a field type called "Custom" that allows me to specific my own regular expression for field validation. Seems like it would be a pretty simple thing to add on but I'm just guessing.
Gravity Forms rocks!
Thanks!
kcm
Hi there. I'd love to have a field type called "Custom" that allows me to specific my own regular expression for field validation. Seems like it would be a pretty simple thing to add on but I'm just guessing.
Gravity Forms rocks!
Thanks!
kcm
That is a good idea, but meanwhile you can add your own custom validation using a hook and a few lines of PHP. If that is something you want to try, I can send you a code snippet.
Hi, Alex. Yes, that would be great. Please send me the code snippet.
Thanks!
kcm
Hi, Alex. Should I email you to get that snippet of code you mentioned?
Thanks!
kcm
Following is a sample code snippet. To get the submitted field value, you can use $_POST["input_XXX"]
add_filter('gform_validation', 'custom_validation');
function custom_validation($validation_result){
// set the form validation to false
$validation_result["is_valid"] = false;
$form = $validation_result["form"];
// specify the first field to be invalid and provide custom validation message
$form["fields"][0]["failed_validation"] = true;
$form["fields"][0]["validation_message"] = "This field is invalid!";
// update the form in the validation result with the form object you modified
$validation_result["form"] = $form;
return $validation_result;
}
Hi Alex, I have a similar question/issue. My client wants us to validate the email field to ensure it's not coming from any free email hosts (they want commercial entities only). Here's their original code snippet for this validation... my question is how do I incorporate this into GF?
Validation code snippet can be found here:
http://dl.dropbox.com/u/19790225/email_form_validation.php
Thanks,
Sean