Require a minimum/maximum word count

add_filter(‘frm_validate_field_entry’, ‘my_custom_validation’, 10, 3); function my_custom_validation($errors, $posted_field, $posted_value){ if ( $posted_field->id == 25 && $posted_value != ” ){ //change 25 to the ID of the field to validate //check the $posted_value here $words = explode(‘ ‘, $posted_value); //separate at each…Continue reading

Clear Javascript

add_filter(‘frm_validate_field_entry’, ‘my_custom_validation’, 10, 2); function my_custom_validation($errors, $posted_field){ if(!current_user_can(‘administrator’)){ //don’t strip javascript submitted by administrators if(!is_array($_POST[‘item_meta’][$posted_field->id])){ $_POST[‘item_meta’][$posted_field->id] = wp_kses_post($_POST[‘item_meta’][$posted_field->id]); }else{ foreach($_POST[‘item_meta’][$posted_field->id] as $k => $v){ if(!is_array($v)) $_POST[‘item_meta’][$posted_field->id][$k] = wp_kses_post($v); } } } return $errors; }Continue reading

Require minimum age

add_filter(‘frm_validate_field_entry’, ‘my_custom_validation’, 10, 3); function my_custom_validation($errors, $posted_field, $posted_value){ if($posted_field->id == 25){ //change 25 to the ID of the field to validate //check the $posted_value here if(strtotime(“-18 years“) < strtotime($posted_value)){ //if birthday is less than 18 years ago //if it doesn’t…Continue reading

Capitalize all text fields

add_filter(‘frm_validate_field_entry’, ‘field_caps_validation’, 8, 3); function field_caps_validation($errors, $posted_field, $posted_value){ if($posted_field->type == ‘text’){ $_POST[‘item_meta’][$posted_field->id] = mb_strtoupper($posted_value); } return $errors; }Continue reading

Force field value back to previous

add_filter(‘frm_validate_field_entry’, ‘my_custom_validation’, 10, 3); function my_custom_validation($errors, $posted_field, $posted_value){ $featured_field = 25; //change 25 to the ID of the featured field if ( ! current_user_can(‘administrator’) && $posted_field->id == $featured_field ) { if ( isset( $_POST[‘id’] ) && $_POST[‘id’] ) { $force_val…Continue reading

Conditionally require a field

add_filter( ‘frm_validate_field_entry’, ‘conditionally_require_a_field’, 10, 3 ); function conditionally_require_a_field( $errors, $field, $value ) { if ( $field->id == 25 && trim( $value ) == ” ) { //change 25 to the ID of the field to require $other_field_value = $_POST[‘item_meta’][20]; //Change…Continue reading

Check for an allowed value (coupons)

add_filter(‘frm_validate_field_entry’, ‘my_custom_validation’, 10, 3); function my_custom_validation($errors, $posted_field, $posted_value){ if($posted_field->id == 25){ //change 25 to the ID of the field to validate if(!in_array($posted_value, array(‘001‘,’002‘))){ //change 001 and 002 to your allowed values //if it doesn’t match up, add an error: $errors[‘field’.…Continue reading

Create a confirmation field

add_filter(‘frm_validate_field_entry’, ‘your_custom_validation’, 20, 3); function your_custom_validation($errors, $field, $value){ if ($field->id == 31){ //change 31 to the ID of the confirmation field (second field) $first_value = $_POST[‘item_meta’][30]; //change 30 to the ID of the first field       if ( $first_value…Continue reading

Combine multiple fields into one field

add_filter(‘frm_validate_field_entry’, ‘my_custom_validation’, 8, 3); function my_custom_validation( $errors, $posted_field, $posted_value ) { if($posted_field->id == 25){ //change 25 to the ID of the destination field //change the value between the quotes to what should go in-between values $separator = “, “; $_POST[‘item_meta’][25]…Continue reading

Limit uploaded file size

add_filter( ‘frm_validate_field_entry’, ‘validate_custom_file_size’, 20, 3 ); function validate_custom_file_size( $errors, $field, $value ) { if ( $field->type == ‘file’ && ( isset( $_FILES[‘file’.$field->id] ) ) && ! empty( $_FILES[‘file’.$field->id][‘name’] ) ) { $files = (array) $_FILES[‘file’. $field->id][‘size’]; foreach ( $files as…Continue reading