Use this shortcode to get the value from a single field entry and display it in a page, post, View or form field. This can be particularly helpful in auto-populating forms for your users.
Usage
Insert the following shortcode in any page, post, View, or field.
[frm-field-value field_id=x user_id=current]
'x' = ID of the field that holds the value you would like to retrieve. If you do not include one of the user_id, entry, or ip parameters, this will retrieve the most recent entry submitted by any user .
Parameters
Required
-
field_id
ID or key of the field that holds the value you would like to retrieve.
You may also include one of these three options in the shortcode:
-
user_id
Get a value from the most recent entry submitted by a specific logged-in user. You may set user_id=current to retrieve the most recent entry submitted by the current user. This is particularly helpful in auto-populating forms for your users. Usage: [frm-field-value field_id=x user_id=current]
-
ip
Get a value from the most recent entry submitted from a specific IP address. You can specify an IP address or use ip=1 to use the IP of the current user. This does not require users to be logged in. Usage: [frm-field-value field_id=x ip=1]
-
entry
Get a value from a specific entry ID or key. If the entry ID/key is in the URL like this: ?pass_entry=12345, you can retrieve the ID from the URL like this: entry=pass_entry. You may also pass the entry ID/key as a parameter in a form or View shortcode. Usage: [frm-field-value field_id=x entry="140"]
[frm-field-value field_id=x entry="entry_param"]
[frm-field-value field_id=x entry="entry-key"]
Optional
-
show
Get the entry ID from a Dynamic field by using show=id. This allows you to autopopulate Dynamic fields. Usage: [frm-field-value field_id=x user_id=current show=id].
Alternatively, you can use show=value to get the saved value from a field with separate values. Usage: [frm-field-value field_id=x user_id=current show=value] -
html
Include the HTML for an uploaded file. By default, this shortcode will return the html, but it can be turned off with html=0. This will return the URL only. Usage: [frm-field-value field_id=x user_id=current html=0]
-
default
Insert a default value in case there isn't a value to retrieve. Usage: [frm-field-value field_id=x user_id=current default="Your name"]
-
format
Specify a format for date or time fields. Usage: [frm-field-value field_id=x user_id=current format="Y-m-d"]
Examples
Automatically populate a date field
By default, the [frm-field-value field_id=x user_id=current] shortcode will display a date in the format selected in your WordPress settings. In order to automatically populate a date field with the frm-field-value shortcode, you can use [frm-field-value field_id=x user_id=current format="Y-m-d"].
Automatically populate an address field
In order to automatically populate an address field, you can use these parameters to pull specific parts of the address field using the frm-field-value shortcode. In the Address field options, insert the frm-field-value shortcode in the Default Value box for each specific field.
In these examples, replace 155 with the field ID/key of the address field from the entry where you're getting the value from.
- Autopopulate the first line of the Street address
[frm-field-value field_id=155 show=line1]
- Autopopulate the second line of the Street address
[frm-field-value field_id=155 show=line2]
- Autopopulate the City
[frm-field-value field_id=155 show=city]
- Autopopulate the State
[frm-field-value field_id=155 show=state]
- Autopopulate the Zip Code
[frm-field-value field_id=155 show=zip]
- Autopopulate the Country
[frm-field-value field_id=155 show=country]
Limitations
This shortcode currently does not work with repeater fields.
Related Customizations
Use a value in a conditional statement
Note: you can now use [frm-field-value] in conditional statements using the built-in frm-condition shortcode. https://formidableforms.com/knowledgebase/compare-two-values-for-display/
Create a new shortcode that allows values from frm-field-value to be used in conditional statements. You can use any parameters in this shortcode that you can use above, plus equals.
[maybe-frm-field-value field_id=x user_id=current equals=5]show it[/maybe-frm-field-value]
Then add this code in your theme functions.php or a new plugin to create the new shortcode:
function maybe_frm_value_func( $atts, $content = '' ) { $val = FrmProEntriesController::get_field_value_shortcode($atts); if($val == $atts['equals']){ return $content; }else{ return ''; } } add_shortcode( 'maybe-frm-field-value', 'maybe_frm_value_func' );
Get the total of two or more fields
This shortcode adds the values of the specified fields in the current user's most recent entries and returns the total. The fields can be from different forms or the same form.
Usage example: [fields-total ids="25,100,113"]
add_shortcode('fields-total','ff_fields_total'); function ff_fields_total($atts){ $defaults = array( 'ids' => '', 'user_id' => 'current', ); $atts = array_merge($defaults, $atts); $ids = explode( ',', $atts['ids'] ); unset( $atts['ids'] ); $total = 0; foreach ( $ids as $id ) { $atts['field_id'] = $id; $total += (int)FrmProEntriesController::get_field_value_shortcode($atts); } return $total; }
You can also get the total of fields using stats, as in this code example:
And you can get the sum of fields in the same form using this code example:
https://formidableforms.com/knowledgebase/php-examples/#kb-calculate-a-total-in-view
PHP Alternative
Get a value by user ID
FrmProEntriesController::get_field_value_shortcode(array('field_id' => x, 'user_id' => 'current'));
Replace 'x' with the ID of the field that holds the value you would like to retrieve.
Get a value by entry ID
FrmProEntriesController::get_field_value_shortcode(array('field_id' => x, 'entry' => $entry_id));
Replace 'x' with the ID of the field that holds the value you would like to retrieve. Make sure $entry_id is set in your code.