<?php
/*
Use case for this is when you have certain characters like "@" that should be disallowed in certain fields. You can add a list.
This was built for text fields with job titles. Tweak as needed.
*/
add_filter( 'gform_field_validation', 'gravity_forms_validate_job_titles', 10, 4 );
function mgravity_forms_validate_job_titles( $result, $value, $form, $field ){
$forms_fields_to_check = array(
//form_id => array( $field_id, $field_id_1, $field_id_2),
30 => array( 10 ),
8 => array( 78 ),
24 => array( 78 ),
26 => array( 78 ),
32 => array( 14 ),
);
if( array_key_exists( $form['id'], $forms_fields_to_check ) ){
$form_id = $form['id'];
if( in_array( intval($field['id']), $forms_fields_to_check[$form_id] ) ){
if( strpbrk( $value, "@") !== false ){
return array( 'is_valid' => false, 'message' => "Job Titles cannot have '@' in them" );
}
}
}
return $result;
}
?>