Contact Pages
Spam protection
Code With ACF Integration
// example add_filter("frm_validate_field_entry", "my_custom_validation2", 10, 8); function my_custom_validation2($errors, $posted_field, $posted_value = null, $args=null){ if($posted_field->id == 114){ if($_POST["item_meta"][$posted_field->id]!="down"){ $errors["field". $posted_field->id] = "That field is wrong!"; } } return $errors; }
It often happens that google capcha will allow spam to pass. To avoid this, it is necessary to make a mandatory field in which it will only be clear to the person what to enter. But what if the functionality is formedable or gravityForms does not allow this. In this case, we tear off functions.php and apply filter through which we can do such processing.
Syntax for Formedable
add_filter(‘frm_validate_field_entry‘, ‘name_of_function’, 10, form-id);
function name_of_function($errors, $posted_field, $posted_value = null, $args=null){
if($posted_field->id == Input-id){
if(mb_strtolower($_POST[‘item_meta’][$posted_field->id])!=’down’){
$errors[‘field’. $posted_field->id] = ‘That field is wrong!’;
}
example:
add_filter(‘frm_validate_field_entry’, ‘my_custom_validation2’, 10, 3);
function my_custom_validation2($errors, $posted_field, $posted_value = null, $args=null){
if($posted_field->id == 24){
if($_POST[‘item_meta’][$posted_field->id]!=’down’){
$errors[‘field’. $posted_field->id] = ‘That field is wrong!’;
}
}
return $errors;
}
Syntax for GravityForms
example:
add_filter(‘gform_validation‘, ‘gfcf_validation’);
function gfcf_validation($validation_result) {
foreach($validation_result[“form”][“fields”] as $field)
{
if($field[“label”]==”What goes up must come ____?”)
{
$value[] = rgpost(“input_{$field[‘id’]}”);
if ($value[0]!=”down”) {
$validation_result[‘is_valid’]=false;
$field[‘failed_validation’] = true;
$field[‘validation_message’] = ‘Your values do not match.’;
}
}
}
return $validation_result;
}
Send Mail When User Get Error Input
Code With ACF Integration
add_filter('frm_validate_entry', 'validate_my_form2', 20, 3); function validate_my_form2($errors, $values){ $keysError=Array(); foreach(array_keys($errors) as $keyer){ array_push($keysError, str_replace("field", "",$keyer)); } $body=""; foreach($keysError as $key){ $highest_field = FrmField::getOne( $key ); $body.= $highest_field->name.": ".$_POST['item_meta'][$key]."
"; } $to = "[email protected]"; $subject = "Logopipe Info"; $headers = array('Content-Type: text/html; charset=UTF-8', 'From: logopipe.com Site'); wp_mail($to, $subject, $body, $headers); return $errors; }
This block of code adds a function to formidable to send an email message when a user fills in an error.
Syntax
add_filter(‘frm_validate_entry’, ‘validate_my_form2’, 20, FormID);
function validate_my_form2($errors, $values){
$keysError=Array();
foreach(array_keys($errors) as $keyer){
array_push($keysError, str_replace(“field”, “”,$keyer));
}
$body=””;
foreach($keysError as $key){
$highest_field = FrmField::getOne( $key );
$body.= $highest_field->name.”: “.$_POST[‘item_meta’][$key].”<br>”;
}
$to = “mail“;
$subject = “Logopipe Info”;
$headers = array(‘Content-Type: text/html; charset=UTF-8’, ‘From: logopipe.com Site <[email protected]>’);
wp_mail($to, $subject, $body, $headers);
return $errors;
}