Formidable Forms

Formidable Forms

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

Get a Value from an Entry

Last Updated: October 31, 2021

Knowledge Base → Entries → Listing Entries → Get a Value from an Entry

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.

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

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.

    [frm-field-value field_id=x]

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.

    [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.

    [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.

    [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"]

    To get the value from a specific entry ID/key filtered by the current logged-in user, use both the entry and the user_id parameters.

    [frm-field-value field_id=x entry="entry_key" user_id="current"]

Optional

  • show

    Get the entry ID from a Dynamic field by using show=id. This allows you to autopopulate Dynamic fields.

    [frm-field-value field_id=x user_id=current show=id]

    You can also get the ID number from a User ID field by using show=id. Replace x with your User ID field ID/key.

    [frm-field-value field_id=x show=id]

    Alternatively, you can use show=value to get the saved value from a field with separate values.

    [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.

    [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.

    [frm-field-value field_id=x user_id=current default="Your name"]
  • format

    Specify a format for date or time fields.

    [frm-field-value field_id=x user_id=current format="Y-m-d"]
✍ Note: When using params for frm-field-value (e.g., field_id and entry), the param is treated as missing if they're left blank or set to 0, and the shortcode will be evaluated accordingly.

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. To automatically populate a date field with the frm-field-value shortcode, use this shortcode:

[frm-field-value field_id=x user_id=current format="Y-m-d"]

Automatically populate an address field

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.
Get Value Address Field Options
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]
  • Get Value Autopopulate Address Field

Using truncate

Use the truncate parameter to specify the number of characters. Replace x with the field ID/key of your field from the entry where you're getting the value from.

  • Truncate text to 2 characters.
    [frm-field-value field_id=x truncate=2]
  • Truncate text to 10 characters.
    [frm-field-value field_id=x truncate=10]
  • Truncate text to 100 characters.
    [frm-field-value field_id=x truncate=100]
  • More Text: By default, this will be "..." but can be changed with the more_text parameter.
    [frm-field-value field_id=x truncate=100 more_text="...Read More"]

Limitations

  • Using [frm-field-value field_id=x truncate=1] will truncate the text to 50 characters. Use this code snippet if you want to override this.
  • This shortcode currently does not work with repeater fields.

Related Customizations

Use a value in a conditional statement

You can use [frm-field-value] in conditional statements using the built-in frm-condition shortcode.
  1. 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]
  2. 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.

[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;
}
  • Use this code example to get the total of fields using stats.
  • Use this code example to get the sum of fields in the same form.

Add custom truncate

To add a custom truncate option to the [frm-field-value] shortcode, follow the example below.

[frm-field-value field_id=x custom_truncate=1]
add_filter('do_shortcode_tag', 'truncate_frm_field_value', 10, 3);
function truncate_frm_field_value($output, $tag, $attr) {
    if ('frm-field-value' === $tag && isset( $attr['custom_truncate'] ) && is_numeric( $attr['custom_truncate'] ) ) {
        $output = FrmAppHelper::truncate($output, $attr['custom_truncate'] );
    }
    return $output;
}

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.

  • Usage
  • Parameters
    • field_id
    • user_id
    • ip
    • entry
    • show
    • html
    • default
    • format
  • Examples
    • Automatically populate a date field
    • Automatically populate an address field
  • Using truncate
  • Limitations
  • Related Customizations
    • Use a value in a conditional statement
    • Get the total of two or more fields
    • Add custom truncate
  • PHP Alternative
    • Get a value by user ID
    • Get a value by entry ID
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.

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