Docs & Support

Learn about all the Formidable features and get support from our amazing customer success team.

frm_validate_field_entry

This hook can be used to create your own custom field validations and errors. The Pro validation is also run using this hook. It runs with a priority of 10. The Pro validation will remove any error messages for fields that are conditionally hidden, so you may want to run your function with a priority below 10.

This hook is run every time the submit button is clicked.

Usage

add_filter('frm_validate_field_entry', 'my_custom_validation', 10, 4);
function my_custom_validation($errors, $posted_field, $posted_value, $args)

Formidable Forms makes advanced site building simple. Launch forms, directories, dashboards, and custom WordPress apps faster than ever before.

Parameters

  • $errors (array)
  • $posted_field (object)
  • $posted_value (string or array)
  • $args (array)
    • 'id' (int)
    • 'parent_field_id' (int)
    • 'key_pointer' (int)
    • 'exclude' (array)

Examples

Change the value in a field

This code will get the value from one field and copy it over to a second field.

add_filter('frm_validate_field_entry', 'copy_my_field', 10, 3);
function copy_my_field($errors, $posted_field, $posted_value){
if ( $posted_field->id == 25 ) { //change 25 to the ID of the field to change
$_POST['item_meta'][$posted_field->id] = $_POST['item_meta'][20]; //Change 20 to the ID of the field to copy
}
return $errors;
}

Require a minimum number of checked values

This code will allow you to require a minimum number of checked boxes in a Checkbox field. Just replace 25 with the ID of your checkbox field and 4 with the minimum number of boxes.

add_filter('frm_validate_field_entry', 'require_minimum_checkbox_number', 10, 3);
function require_minimum_checkbox_number( $errors, $field, $posted_value ){
if ( $field->id == 25 ) {
$minimum = 4;
if ( ! is_array ( $posted_value ) || ( is_array( $posted_value ) && count( $posted_value ) < $minimum ) ) {
$errors['field' . $field->id] = 'Please select at least ' . $minimum . ' items.';
}
}
return $errors;
}

Conditionally require a field

If you would like a field to be required only when a certain value is selected in another field, you can do it without code by marking the field required and using conditional logic on that field to hide it when it's not required. But if you would like the field to always be available, but only sometimes required, this example will help. Be sure you do not mark the field required in your settings.

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 20 to the ID of the field to check
if ( $other_field_value == 'Today' ) { // change 'Today' to the value needed to make this required
$errors[ 'field'. $field->id ] = 'That field is required';
}
}
return $errors;
}

Check for an allowed value (coupons)

This code checks if a certain field has an allowed value. If it does not have an allowed value, an error is returned. This can be used to validate coupon codes or responses.

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'. $posted_field->id] = 'That field is wrong!';
}
}
return $errors;
}

Create a confirmation field

Update: This feature is now built in so this customization is no longer necessary. Read more about using confirmation fields

Use this code to make sure two fields have exactly the same value entered. This is often used to verify that email addresses and passwords are correctly entered.

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 != $value && !empty($value) ) {
     $errors['field'. $field->id] = 'The email addresses entered do not match.';//Customize your error message
   }else{
$_POST['item_meta'][$field->id] = ''; //if it matches, this clears the second field so it won't be saved
}
}
return $errors;
}

Combine multiple fields into one field

Before you begin with custom code, it's very likely that the built-in text calculations will help.

Use this code to combine the values of more than one field into a single field. In this example, 25 is the Field ID of the field that will receive the values of the others, which will be linked together in the order listed, and separated by a comma followed by a single space.

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] =
$_POST['item_meta'][20] . $separator .
$_POST['item_meta'][21] . $separator .
$_POST['item_meta'][22] . $separator .
$_POST['item_meta'][23];
//change each number (20, 21, 22, 23) to the ID of the fields to insert
}
return $errors;
}

Limit uploaded file size

Use this code to limit the maximum file size that can be uploaded from a file upload field. This will apply to all file upload fields.

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 $v ) {
if ( $v > 100000 ) {//change this number to the max size you would like. 100000 bytes = 100 KB
$errors['field'.$field->id] = 'That file is too big. It must be less than 100KB.';
}
}
}
return $errors;
}

Limit number of uploaded files

This code can be used to limit the number of files that can be uploaded in a file upload field. This will apply to all multiple file upload fields.

add_filter('frm_validate_field_entry', 'validate_number_of_files', 10, 3);
function validate_number_of_files($errors, $field, $value){
if ( in_array($field->id, array(25,26,27)) && $field->type == 'file' && (isset($_FILES['file'.$field->id])) && !empty($_FILES['file'.$field->id]['name'])){
$files = (array)$_FILES['file'. $field->id]['name'];
$count = 0;
foreach($files as $n){
if(!empty($n))
$count++;
}
$existing = $_POST['item_meta'][$field->id];
if($existing){
foreach($existing as $e){
if(!empty($e))
$count++;
}
}
if ($count > 3){ //change 3 to the allowed number of files
$errors['field'.$field->id] = 'Please limit your selection to 3 files.';
}
}
return $errors;
}

Change 25, 26, and 27 to your file upload field IDs, or remove in_array($field->id, array(25,26,27)) if you want this to apply to all file upload fields.

Limit each user to one entry per option

If you have a dropdown field with 3 options, the same user will be able to submit the form once for each option. If the same option is selected twice, the form will not pass validation.

add_filter('frm_validate_field_entry', 'my_custom_validation', 10, 3);
function my_custom_validation($errors, $posted_field, $posted_value){
if($posted_field->id == 125 and !is_admin()){ //change 125 to the ID of the field to validate
global $wpdb, $user_ID;
$entry_id = (isset($_POST['id'])) ? $_POST['id'] : 0;
$entries = $wpdb->get_col($wpdb->prepare("SELECT item_id FROM ". $wpdb->prefix ."frm_item_metas em LEFT JOIN ". $wpdb->prefix ."frm_items e ON (em.item_id = e.id) WHERE em.field_id=%d AND em.meta_value=%s AND item_id != %d AND user_id = %d", $posted_field->id, $_POST['item_meta'][$posted_field->id], $entry_id, $user_ID));
if(count($entries) >= 1) //limit to one entry per option.
$errors['field'. $posted_field->id] = 'You have already selected that option';
}
return $errors;
}

Limit the combination of two fields

You may have the need to require the combination of two fields to be unique. You may use the code below to make sure two fields are unique. Please note: This does not currently work with post fields.

add_filter('frm_validate_field_entry', 'two_fields_unique', 10, 2);
function two_fields_unique( $errors, $posted_field ) {
$first_field_id = 125; // change 125 to the id of the first field
$second_field_id = 126; // change 126 to the id of the second field
if ( $posted_field->id == $first_field_id ) {
$entry_id = isset( $_POST['id'] ) ? absint( $_POST['id'] ) : 0;
$values_used = FrmDb::get_col( 'frm_item_metas',
array( 'item_id !' => $entry_id,
array( 'or' => 1,
array( 'field_id' => $first_field_id, 'meta_value' => $_POST['item_meta'][ $first_field_id ] ),
array( 'field_id' => $second_field_id, 'meta_value' => $_POST['item_meta'][ $second_field_id ] ),
)
), 'item_id', array( 'group_by' => 'item_id', 'having' => 'COUNT(*) > 1' )
);
if ( ! empty( $values_used ) ) {
$errors[ 'field'. $first_field_id ] = 'You have already selected that option';
$errors[ 'field'. $second_field_id ] = 'You have already selected that option';
}
}
return $errors;
}

Calculate total time

Use this code to calculate a total time from a start and end time. This example is designed to work with time fields set to show as a single dropdown.

add_filter('frm_validate_field_entry', 'calculate_time', 11, 3);
function calculate_time($errors, $field, $value){
if($field->id == 25){ //change 25 to the ID of the hidden or admin only field which will hold the calculation
$start = strtotime($_POST['item_meta'][23]); //change 23 to the ID of the first field
$end = strtotime($_POST['item_meta'][24]); //change 24 to the ID of the second field
$totaltime = ($end - $start);
$hours = intval($totaltime / 3600);
$seconds_remain = ($totaltime - ($hours * 3600));
$minutes = intval($seconds_remain / 60);
//$seconds = ($seconds_remain - ($minutes * 60)); Uncomment this line if you want seconds calculated.
$leading_zero_for_minutes = $minutes < 10 ? '0' : '';
//$leading_zero_for_seconds = $seconds < 10 ? '0' : '';//Uncomment this line if you're including seconds.
$totaltime = $hours . ':' . $leading_zero_for_minutes . $minutes;
//$totaltime = $hours . ':' . $leading_zero_for_minutes . $minutes . ':' . $leading_zero_for_seconds . $seconds;//uncomment this line if you're including seconds
$value = $_POST['item_meta'][ $field->id ] = $totaltime;
}
return $errors;
}
 

Clear Javascript

Javascript will not be processed by default, but you can use a bit of added code to strip the javascript before save. No changes are needed to this example.

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;
}

Require minimum age

Make sure a user is at least 18 years old before allowing them to submit your form. First, add a date field to your form for birthdates, then add this custom code to check the selected date.

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 match up, add an error:
$errors['field'. $posted_field->id] = 'That field is wrong!';
}
}
return $errors;
}

Capitalize all text fields

Use this code to capitalize all values entered in text fields when an entry is submitted.

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;
}

Verify dropdown/radio options

There are times you may need to be absolutely sure a value saved in your dropdown/radio field is one of the provided options.

add_filter('frm_validate_field_entry', 'frm_check_radio_option', 10, 3);
function frm_check_radio_option( $errors, $posted_field, $posted_value ) {
$field_ids = array( 25, 26 ); // set your field ids here
if ( in_array( $posted_field->id, $field_ids ) && ! empty( $_POST['item_meta'][ $posted_field->id ] ) ) {
$options = $posted_field->options;
$in_options = false;
foreach ( $options as $opt_key => $opt ) {
$saved_value = FrmFieldsController::check_value( $opt, $opt_key, $posted_field );
if ( $_POST['item_meta'][ $posted_field->id ] == $saved_value ) {
$in_options = true;
break;
}
}
if ( ! $in_options ) {
$errors[ $posted_field->id ] = 'That is not an option';
}
}
return $errors;
}

Save the date in a different format

When you integrate with other plugins, some may expect a format other that the standard yyyy-mm-dd the Formidable uses. In this case, you can add a hidden field to your form, and use custom code to fill it with the date in the format you need.

add_filter('frm_validate_field_entry', 'copy_my_field', 10, 3);
function copy_my_field($errors, $posted_field, $posted_value){
if ( $posted_field->id == 25 ) { //change 25 to the ID of the hidden field to change
$oDate = $_POST['item_meta'][77]; // change 77 to the ID of your date field
$_POST['item_meta'][$posted_field->id] = strtotime($oDate);
}
return $errors;
}

Validate field in repeating section

add_filter('frm_validate_field_entry', 'my_custom_validation', 10, 4);
function my_custom_validation($errors, $posted_field, $posted_value, $args){
if($posted_field->id == 102){ //change to the ID of the field to validate
if(!in_array($posted_value, array(123456,987654,234567))){ //enter your allowed values
//if it doesn't match up, add an error:
$errors['field'. $args['id']] = 'Not a Valid Serial Number';
}
}
return $errors;
}

Redirect User if Already Registered

This example can be used to redirect a user to a different URL if they try registering (using the Registration plugin) when they have already registered.

add_filter('frm_validate_field_entry', 'maybe_redirect', 10, 3);
function maybe_redirect( $errors ){
if ( isset( $errors['field'. 799 ]) && $errors['field'. 799 ] == 'This email address is already registered.' ) { //change 799 to your email field id
wp_redirect('http://www.google.com'); //change the url to the URL you want users redirected to
exit;
}
return $errors;
}

Copy text value from Dynamic field

This code will get the text value from a Dynamic field and copy it over to a second field.

  • Replace 125 with the ID of the field to change
  • Replace 120 with the ID of the Dynamic field to copy
  • Replace 50 with the ID of the linked field that the Dynamic field loads entries from
add_filter('frm_validate_field_entry', 'copy_my_dynamic_field', 10, 3);
function copy_my_dynamic_field( $errors, $posted_field, $posted_value ) {
if ( $posted_field->id == 125 ) {
$_POST['item_meta'][ $posted_field->id ] = FrmProEntriesController::get_field_value_shortcode( array( 'field_id' => 50, 'entry' => $_POST['item_meta'][120] ) );
}
return $errors;
}

Combine date and time

Do you need to filter a view by a date and time? Combine the two into a single field to make this possible.

add_filter( 'frm_validate_field_entry', 'frm_combine_date_time', 8, 2 );
function frm_combine_date_time( $errors, $posted_field ) {
$date_field = 25; // change 25 to the id of your date field
$time_field = 26; // change 26 to the id of your time field
$combo_field = 27; // change 27 to the id of your hidden combo field
if ( $posted_field->id == $combo_field ) {
$date = FrmProAppHelper::maybe_convert_to_db_date( sanitize_text_field( $_POST['item_meta'][ $date_field ] ), 'Y-m-d' );
$time = sanitize_text_field( $_POST['item_meta'][ $time_field ] );
FrmProTimeField::time_array_to_string( $time );
$time = FrmProAppHelper::format_time( $time, 'H:i:s' );
$_POST['item_meta'][ $combo_field ] = $date . ' ' . $time;
}
return $errors;
}

Combine auto increment field with another field

Use this code to combine the text in an auto increment field with the text in another field safely. This code runs after any adjustments to the auto increment field would have been made. (The initial numbers in auto increment fields can be changed on form submission if multiple forms are started around the same time.)

Replace 56 with the ID of the field that holds the combination of the auto increment field and the other field. Replace 54 and 55 with the IDs of the auto increment field and the other field. Enter them in the order you want them combined.

add_filter('frm_validate_field_entry', 'combine_auto_id_with_field', 15, 3);
function combine_auto_id_with_field( $errors, $posted_field, $posted_value ) {
if($posted_field->id == 56){ //change 56 to the ID of the destination field
$_POST['item_meta'][56] = $_POST['item_meta'][54] . $_POST['item_meta'][55];
//change 54 and 55 to the IDs of the auto increment field and the other field, in the order you want them combined.
}
return $errors;
}

Validate password field

Use this code if you want to force the user to enter a password with at least 8 characters, including at least one letter and one number.

add_filter('frm_validate_field_entry', 'check_user_pass', 10, 3);
function check_user_pass($errors, $posted_field, $posted_value){
if($posted_field->id == 6369){ //change 6369 to the ID of the password field to validate
if(!preg_match('/^(?=.*[A-Za-z])(?=.*d)[A-Za-z!@#$%&*()?d]{8,}$/', $posted_value)) {
$errors['field'. $posted_field->id] = 'Password must be at least 8 characters long and contain at least 1 number and 1 letter';
}
}
return $errors;
}

Round robin assignments

As users submit their forms, you can assign them to two different groups in round robin fashion, with one user assigned to group "orange" and the next assigned to group "green."  You can modify this code to have more than two groups.  You can also use this code to, say, give a prize to every 100th person who fills out the form. Your form should have a field with a default value of [auto_id] and a field where the group name (or prize info or whatever you want) will be stored.

add_filter( 'frm_validate_field_entry', 'frm_set_value_based_on_order', 15, 3 );
function frm_set_value_based_on_order( $errors, $posted_field, $posted_value ) {
   if ( $posted_field->id == 175 ) { //change 175 to the ID of your group name field
      $group_id   = $_POST['item_meta'][174] % 2;//change 174 to your auto_id field and 2 to the number of groups you have
      $group_name = "unassigned";//change "unassigned" to your default value
      switch ( $group_id ) {
         case 0:
            $group_name = "orange";//change "orange" to the name of your group
            break;
         case 1:
            $group_name = "green";//change "green" to the name of your group
            break;
      }//add additional cases for additional groups, as you'd like

      $_POST['item_meta'][175] = $group_name;//change 175 to the ID of your group name field
   }
return $errors;
}

Calculate time between dates + times

Use this code to calculate a total time between a start and end date and time. Replace m/d/Y with the format selected in your Formidable Global Settings. Replace 23, 24, 25, and 26 with your field IDs.

add_filter('frm_validate_field_entry', 'calculate_time', 11, 3);
function calculate_time($errors, $field, $value){
  if($field->id == 30){ //change 30 to the ID of the hidden or admin only field which will hold the calculation
    $start_date = date_create_from_format( 'm/d/Y', $_POST['item_meta'][23] ); // Change 23 to the ID of the first date field
    $start_date = date_format( $start_date, 'Y-m-d' );
	$start = strtotime( $start_date . ' ' . $_POST['item_meta'][24] ); // Change 24 to the ID of the first time field
	$end_date = date_create_from_format( 'm/d/Y', $_POST['item_meta'][25] ); // Change 25 to the ID of the second date field
	$end_date = date_format( $end_date, 'Y-m-d' );
	$end = strtotime( $end_date . ' ' . $_POST['item_meta'][26] ); // Change 26 to the ID of the second time field

	$totaltime = human_time_diff( $start, $end );
	$_POST['item_meta'][ $field->id ] = $totaltime;
}
return $errors;
}

Set custom value in repeating field

Use the code below to set a custom value in a repeating field. Replace 508 with the ID of the repeating section field. Replace 11700 with the ID of the field that you want to modify.

add_filter('frm_validate_field_entry', 'set_custom_repeating_val', 10, 4);
function set_custom_repeating_val($errors, $posted_field, $posted_value, $args){
        if ( $posted_field->id == 508 ) {
            $field_to_change = 11700;
			if ( ! isset( $_POST['item_meta'][ $posted_field->id ] ) ) {
				return $errors;
			}
			foreach ( $_POST['item_meta'][ $posted_field->id ] as $row_num => $section_vals ) {
				if ( $row_num === 'form' ) {
				continue;
				}

			$_POST['item_meta'][ $posted_field->id ][ $row_num ][ $field_to_change ] = 'new val';
			}
		}
return $errors;
}

Calculate final date

If you need to get a second date based on an entered date and number of days, you may use the code below. Replace 25 with the ID of the date field that you want to populate with code. Replace 20 with the ID of the date field that you will use in your calculation. Replace +7 day with any PHP safe date string.

add_filter('frm_validate_field_entry', 'set_my_expiration_date', 10, 3);
function set_my_expiration_date($errors, $posted_field, $posted_value){
        if ( $posted_field->id == 25 ) { //change 25 to the ID of the date field to change
			// Get the first date in a UNIX timestamp
			$first_date = date_create_from_format( 'd/m/Y', $_POST['item_meta'][20] ); //Change 20 to the ID of the first date field and change d/m/Y to the format on your Formidable -> Global settings page
			$first_date = date_format( $first_date, 'Y-m-d' );
			$first_date = strtotime( $first_date );

			// Get the final date in Y-m-d format
			$final_date = strtotime('+7 day', $first_date);
			$final_date = date('Y-m-d', $final_date);

			// Save the final date as the posted value
			$_POST['item_meta'][$posted_field->id] = $final_date;
		}
return $errors;
}

Make sure to change d/m/Y to the date format selected in your Formidable Global Settings.

Require a minimum/maximum word count

Require a minimum, maximum, or range for a required number of words (or characters) in a field. Notes:

  • this code example is not written to work with fields that are in Repeatable Sections.
  • Additional note: this code example is set up for a maximum word count. If you want a minimum word count or range, please uncomment and/or comment the code as indicated.
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 space
    $count = count($words); //count each word
    // $count = strlen($posted_value); //uncomment this line to count characters instead of words
    //
    //uncomment the next two lines create a minimum value and error message
    //if($count id] = 'That is not long enough.';
			
    //comment the next two lines if you only want a minimum value and error message
    if($count > 300) //change "300" to fit your maximum limit
       $errors['field'. $posted_field->id] = 'That is too long.';
    //uncomment both pairs above to create a range
  }
  return $errors;
}

Make sure to change d/m/Y to the date format selected in your Formidable Global Settings.

Force field value back to previous

It's possible for a malicious user to change the values of hidden fields. Depending on the situation, this may or may not be acceptable. The code will make sure that only an admin user can change the value of this field. Replace 25 with the ID of the field that you want to limit and replace 'No' with the default value that you would like to force when a new entry is created.

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 = FrmProEntriesController::get_field_value_shortcode(array('field_id' => $posted_field->id, 'entry_id' => $_POST['id']));
        } else {
            $force_val = 'No';
        }
if ( $_POST['item_meta'][$posted_field->id] != $force_val ) {
$_POST['item_meta'][$posted_field->id] = $force_val;
}
}
return $errors;
}

Limit the number of times a date can be selected

add_filter('frm_validate_field_entry', 'my_custom_validation', 10, 3);
function my_custom_validation($errors, $posted_field, $posted_value){
  if($posted_field->id == 125 and !is_admin()){ //change 125 to the ID of the date field
    $frmpro_settings = FrmProAppHelper::get_settings();
    $selected_date = FrmProAppHelper::convert_date($posted_value, $frmpro_settings->date_format, 'Y-m-d');
    //get all the entries for that date
    $entries_for_date = FrmEntryMeta::get_entry_metas_for_field(125, '', '', array('value'=> $selected_date)); //change 125 to the ID of the date field
if(count($entries_for_date) >= 3) //change allowed count here
$errors['field'. $posted_field->id] = 'That date is full!';
}
return $errors;
}

Limit responses for a set time period

Limit the number of times a response can be used in a field within a certain time period, start with this example. The easiest option would be to go to the settings page for your form and select the option to "Allow Only One Entry for Each Saved Cookie" and set your hours in the "Cookie expiration" box. If that option is not strict enough for your needs, this custom code will be required.

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 and !is_admin()){ //change 25 to thema ID of the field to validate
    global $wpdb;
    $entry_id = (isset($_POST['id'])) ? $_POST['id'] : 0;
    $entries = $wpdb->get_col($wpdb->prepare("SELECT item_id FROM " . $wpdb->prefix . "frm_item_metas em LEFT JOIN " . $wpdb->prefix . "frm_items e ON (em.item_id = e.id) WHERE e.created_at > %s AND em.meta_value=%s AND item_id != %d", date('Y-m-d H:i:s', strtotime('-24 hours')), $_POST['item_meta'][$posted_field->id], $entry_id)); //change -24 hours to the time range to allow
    //$entries = $wpdb->get_col( $wpdb->prepare( "SELECT item_id FROM " . $wpdb->prefix . "frm_items e WHERE item_id != %d AND form_id = %d", $entry_id, $posted_field->form_id ) ); // use this line instead to limit the form to 3 entries
if(count($entries) >= 3) //change allowed count here
$errors['field'. $posted_field->id] = 'That has been submitted today!';
}
return $errors;
}

Keep the default value

Use the code below to save the default value in a field, even if the user has changed the value using browser developer tools. With this, a user won't be able to change a value in a field that's hidden, set to read only, or otherwise restricted. This code works with default values that are explicitly set (e.g. "100" or "gold") or that use standard WordPress shortcodes (i.e. a shortcode that works on a WordPress page). It won't work with special Formidable shortcodes, like [get param] or [date], that aren't standard WordPress shortcodes.

add_filter( 'frm_validate_field_entry', 'ff_keep_default_value', 10, 3 );
function ff_keep_default_value( $errors, $posted_field, $posted_value ) {
	$fields = array( 166, 168, 169 ); //change 166, 168, 169 to the IDs of the fields whose defaults you want to keep.  Include as many fields as you want.
	if ( in_array( $posted_field->id, $fields ) ) {
		$field_id      = $posted_field->id;
		$field         = FrmField::getOne( $field_id );
		$default_value = "";
		if ( $field && isset( $field->default_value ) ) {
			$default_value = $field->default_value;
		}
		$default_value                   = do_shortcode( $default_value );
		$_POST['item_meta'][ $field_id ] = $default_value;
	}return $errors;}

Change 166, 169, and 169 to the IDs of the fields whose defaults you want to keep. You can list as many fields as you like, separated with commas. They can be from different forms..

Was this article helpful? *

This article may contain affiliate links. Once in a while, we earn commissions from those links. But we only recommend products we like, with or without commissions.

In this article

    We have a small, but amazing team of dedicated people who are committed to helping you achieve your goals and project requirements.


    Copyright © 2025 Strategy11, LLC. Formidable Forms® is a registered trademark Strategy11, LLC.

    Complete your purchase
    Special offer unlocked.
    Get 55% OFF!
    Complete Purchase
    Join 400,000+ using Formidable Forms to create form-focused solutions fast. Get Formidable Forms