Can you please help me? Here's what I tried, but it didn't work.
First, you can view the form at http://www.virtuecard.org. All I want, are for the fields to be required, but since I'm using default values someone can click the "request an invitation" button and it will submit the default values "name" and "email". However, if they do click this I want it to give an error message. Make sense?
The form ID is 13 and the "name" field is field 4 and the "email" field is field 3.
Here's the code I added to my functions.php file that didn't work. I only attempted fixing field 4, but since that didn't work, I didn't code out for field 3 yet.
Can you please tell me the correct code I should use?
-----
<?php
add_filter('gform_validation_13', 'custom_validation');
function custom_validation($validation_result){
$form = $validation_result["form"];
//supposing we don't want input 1 to be a value of 86
if($_POST['input_4'] == name){
// set the form validation to false
$validation_result["is_valid"] = false;
//finding Field with ID of 1 and marking it as failed validation
foreach($form["fields"] as &$field){
//NOTE: replace 1 with the field you would like to validate
if($field["id"] == "4"){
$field["failed_validation"] = true;
$field["validation_message"] = "This field is invalid!";
break;
}
}
}
//Assign modified $form object back to the validation result
$validation_result["form"] = $form;
return $validation_result;
}
?>
Posted 11 years ago on Friday June 28, 2013 |
Permalink