Formidable Forms

Formidable Forms

  • Features
  • Pricing
  • Resources
    • Docs & Support
    • Blog
    • Community
  • Solutions
    • Web Applications
    • Calculators
    • Surveys
    • Directories
    • Payments
    • Contact forms
  • Login
  • Get Formidable Forms

frm_setup_edit_fields_vars

Last Updated: August 30, 2021

Knowledge Base → Extend Formidable Forms → Formidable Hooks - for Developers → Field Options and Values → frm_setup_edit_fields_vars
Heads up!
This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.

This hook can be used to change field values, options, and other field settings when editing an entry.

Formidable Forms is the best WordPress Form Builder plugin. Get it for free!

Usage

add_filter('frm_setup_edit_fields_vars', 'my_custom_function', 20, 4);
function my_custom_function($values, $field, $entry_id)

Parameters

  • $values (array)
  • $field (object)
  • $entry_id (int)
  • $args (array) - can include the following:

Examples

Set fields to read-only when editing

Use this code to make certain fields read-only when editing the entry on the front-end. Limitation: This hook does not work when a Lookup field is watching another Lookup field.

add_filter('frm_setup_edit_fields_vars', 'frm_set_read_only', 20, 3);
function frm_set_read_only($values, $field, $entry_id){
	// If on the back-end, keep fields editable
	if ( FrmAppHelper::is_admin() ) {
	  return $values;
  	}

	// If on front-end, make specific fields read-only
	if ( in_array( $field->id, array( 1558,554,555,556 ) ) ) { 
	   $values['read_only'] = 1;
	}	
	return $values;
}

Set field value when editing

Use this code to set a field value when editing.

add_filter('frm_setup_edit_fields_vars', 'frm_set_edit_val', 20, 3);
function frm_set_edit_val( $values, $field, $entry_id ) {
if ( $field->id == 171 ) { //Replace 171 with your field ID
	// If on the back-end, don't adjust field value
	if ( FrmAppHelper::is_admin() ) {
	  return $values;
  	}

	// If on front-end set a specific field value
        $values['value'] = 'new value';
}
return $values;
}

Show Removed Option

If an option is removed from a radio, dropdown, or checkbox field, previous entries are not affected. However, if those older entries are edited, the selected value will be missing and cannot be selected. This snippet will show the option in the field when editing.

add_filter('frm_setup_edit_fields_vars', 'show_removed_options', 25, 2);
function show_removed_options( $values, $field ) {
	if ( FrmAppHelper::is_admin_page('formidable') || empty( $values['value'] ) ) {
		return $values;
	}
		
	if ( in_array( $field->type, array( 'select', 'radio', 'checkbox' ) ) ) {
		if ( ! in_array( $values['value'], $values['options'] ) ) {
			$values['options'][ $values['value'] ] = $values['value'];
		}
	}
	return $values;
}

Copy field value

Use the code below to set a value, typically in a hidden field, to the current value of another field. This is helpful if you want to compare the two fields after the entry is updated to see if the original field value was updated.

add_filter('frm_setup_edit_fields_vars', 'frm_copy_field_value_before_edit', 20, 3);
function frm_copy_field_value_before_edit( $values, $field, $entry_id ) {
        if ( $field->id == 171 ) { //Replace 171 with the field ID of the field that you want to store the original entry in
		// If on the back-end, don't adjust field value
		if ( FrmAppHelper::is_admin() ) {
			return $values;
		}

		// If on front-end set a specific field value
		$args = array(
                        'field_id' => $field->id, //change $field->id to the ID of the field that has the original entry
			'entry' => $entry_id,
		);

		$values['value'] = FrmProEntriesController::get_field_value_shortcode( $args );
	}
	
	return $values;
}

Copy multiple field values

Use the code below to save the original values of multiple fields in Hidden (or other types of) fields. This is helpful if you want to see if there have been changes to multiple fields when the entry is edited.

For the field pairs, put the id of the Hidden field to the left of the arrow and the id of the original field (the one you want to copy) on the right. You can add as many additional pairs as you'd like or remove pairs, if you have fewer than three.

add_filter('frm_setup_edit_fields_vars', 'frm_copy_multiple_field_values_before_edit', 20, 3);
function frm_copy_multiple_field_values_before_edit( $values, $field, $entry_id ) {
	if ( FrmAppHelper::is_admin() ) {  //don't copy the field value if the entry is edited in the admin area
		return $values;
	}

	$field_pairs = array( //for each pair of fields, put the id of the copy on the left and the original field on the right
		7327 => 7326,
		7329 => 7328,
		7331 => 7330,
	);

	if ( ! empty( $field_pairs[$field->id])){
		$args = array(
			'field_id' => $field_pairs[$field->id],
			'entry' => $entry_id,
		);

		$values['value'] = FrmProEntriesController::get_field_value_shortcode( $args );
	}

	return $values;
}

Count number of edits

Use this code example to count the number of edits to an entry. Usage: Add a Hidden or other field to your form to store the number of times the entry has been edited. Set the default value of this field to 0.

add_filter( 'frm_setup_edit_fields_vars', 'frm_edit_counter', 20, 4 );
function frm_edit_counter( $values, $field, $entry_id ) {
	if ( intval( $field->id ) === 12283 && ! FrmAppHelper::is_admin() ) { //Replace 12283 with your field ID
		$values['value'] = intval( $values['value'] ) + 1;
	}

	return $values;
}

Note: Edits made in the admin area won't be included in the count.

Redirect to Referrer URL after editing

Use this code example to redirect the user to the referring URL after setting up front-end editing. Usage: Add a hidden field to your form and use this field ID in the 'Redirect to URL' box.

add_filter('frm_setup_edit_fields_vars', 'frm_set_checked', 20, 3);
function frm_set_checked($values, $field, $entry_id){
	if ( in_array( $field->id, array(210) ) ) { //Replace 210 with your hidden field ID
		$values['value'] = $_SERVER['HTTP_REFERER'];
	}
	return $values;
}
  • Usage
  • Parameters
  • Examples
    • Set fields to read-only when editing
    • Set field value when editing
    • Show Removed Option
    • Copy field value
    • Copy multiple field values
    • Count number of edits
    • Redirect to Referrer URL after editing
Categories
×

Categories

  • Installation & Getting Started
  • Account Management
  • Forms
  • Entries
  • Views
  • Styles
  • Importing & Exporting
  • Add-Ons
  • Extend Formidable Forms

Using WordPress and want to get Formidable Forms for free?

Get Formidable Forms Lite Now

You do not have permission to view this form. Maybe you need to log in?

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.

Take on bigger projects Right Now

Get the tools you need to revolutionize your workflow and architect a masterpiece. Build the most advanced WordPress forms and actually use the data you collect in meaningful ways.

Get the most advanced WordPress form plugin and the only form builder with integrated Views.

Get Formidable Forms Now

Resources

  • Community
  • Affiliates
  • Contact
  • Free Online Form Builder

Top Features

  • Application Builder
  • Calculator Forms
  • Surveys & Polls
  • Quiz Maker
  • Form Templates
  • Application Templates
  • Directories
  • Donation Plugin

Company

  • About Us
  • Giving Back
  • Careers
  • Newsletter
  • WP Tasty
  • Nutrifox

Copyright © 2023 Strategy11, LLC. Formidable FormsĀ® is a registered trademark Strategy11, LLC.
Privacy Policy | Terms of Service | Sitemap

Join 300,000+ using Formidable Forms to create form-focused solutions fast. Get Started See User Reviews