Form Body CSS Selectors

Form Body CSS Selectors

ContainerField ListContainerList ItemsField InputsInput ContainerDescription ContainerRequired Field Indicator (Asterisk)

Container
Contains the main form content

example: the form body section (div) – applies to all forms
1body .gform_wrapper .gform_body  {border: 1px solid red}

example: the form body section (div) – applies just to form ID #1
1body #gform_wrapper_1 .gform_body {border: 1px solid red}

Field List
Container
unordered list used to structure all of the form elements

example: the form list container (ul) – applies to all forms
1body .gform_wrapper .gform_body .gform_fields {border: 1px solid red}

example: the form list container (ul) – applies just to form ID #1
1body #gform_wrapper_1 .gform_body .gform_fields {border: 1px solid red}

List Items
Individual list items containing each form element

example: the form list item (li) – applies to all forms
1body .gform_wrapper .gform_body .gform_fields .gfield {border: 1px solid red}

example: the form list item (li) – applies just to form ID #1
1body #gform_wrapper_1 .gform_body .gform_fields .gfield {border: 1px solid red}

Field Inputs
Input Container
Wraps the actual form element inside the containing list item

example: input field container (div) – applies to all forms
1body .gform_wrapper .gform_body .gform_fields .gfield .ginput_container {border: 1px solid red}

example: input field container (div) – applies just to form ID #1
1body #gform_wrapper_1 .gform_body .gform_fields .gfield .ginput_container {border: 1px solid red}

example: input field container (div) – applies just to specific form field (based on the unique parent element ID – replace 「XX_X」 with your actual element ID)
1body .gform_wrapper .gform_body .gform_fields  #field_XX_X.gfield .ginput_container {border: 1px solid red}

Description Container
Contains the field description inside the containing list item

example: input field description container (div) – applies to all forms
1body .gform_wrapper .gform_body .gform_fields .gfield .gfield_description {border: 1px solid red}

example: input field description container (div) – applies just to form ID #1
1body #gform_wrapper_1 .gform_body .gform_fields .gfield .gfield_description {border: 1px solid red}

example: input field description container (div) – applies just to specific field description (based on the unique parent element ID – replace 「XX_X」 with your actual element ID)
1body .gform_wrapper .gform_body .gform_fields  #field_XX_X.gfield .gfield_description {border: 1px solid red}

Required Field Indicator (Asterisk)

example: required field indicator (span) – applies to all forms
1body .gform_wrapper .gform_body .gform_fields .gfield .gfield_label .gfield_required {color: red}

example: required field indicator (span) – applies just to form ID #1
1body #gform_wrapper_1 .gform_body .gform_fields .gfield .gfield_label .gfield_required {color: red}

example: required field indicator (span) – applies just to specific indicator (based on the unique parent element ID – replace 「XX_X」 with your actual element ID)
1body .gform_wrapper .gform_body .gform_fields  #field_XX_X.gfield .gfield_label .gfield_required {color: red}

Form Confirmation CSS Selectors

Form Confirmation CSS Selectors

Inline Confirmation Message

Inline Confirmation Message
Displays on same page upon successful completion of the form

example: inline confirmation message (div) – applies to all forms
body .gform_confirmation_wrapper .gform_confirmation_message {border: 1px solid red;}

example: inline confirmation message (div) – applies to form id 1
body #gform_confirmation_wrapper_1 .gform_confirmation_message {color: black;}

Form Data

Form Data

IntroductionUsagePropertiesLine ItemHooks

Introduction
Form Data ($form_data) is an associative array containing the payment related properties for the entry being processed by the Authorize.Net add-on which extends the GFPaymentAddOn class. It is populated using the values from the Submission Data Object generated during form validation.
Usage
We recommend accessing the properties in $form_data using the rgar() function, e.g.:
1$form_data = rgar( $submission_data, 'payment_amount' );

Properties

form_title string
The form title.

email string
The value of the field which was mapped to the billing information Email field.

address1 string
The value of the field which was mapped to the billing information Address field.

address2 string
The value of the field which was mapped to the billing information Address 2 field.

city string
The value of the field which was mapped to the billing information City field.

state string
The value of the field which was mapped to the billing information State field.

zip string
The value of the field which was mapped to the billing information Zip field.

country string
The value of the field which was mapped to the billing information Country field.

first_name string
The Credit Card cardholder first name.

last_name string
The Credit Card cardholder last name.

amount float
Either the form total or the value of the field mapped to the feeds payment amount or recurring amount setting.

fee_amount integer
Zero or the value of the field mapped to the setup fee setting.

line_items array
An indexed array of line items with unit prices greater than or equal to zero. Created from the submitted pricing fields. See Line Item for available properties.

Line Item
12345678array(    'item_id'          => 1,    'item_name'        => 'Product A',    'item_description' => '',    'item_quantity'    => '1',    'item_unit_price'  => 10,    'item_taxable'     => 'Y',)
Each line item is an associative array containing the following properties.

item_id integer
The field ID.

item_name string
The product name or shipping name.

item_description string
Comma separated string of selected option names.

item_quantity integer
The quantity.

item_unit_price float
The total unit price for the product and any selected options or the shipping price.

item_taxable string
Is the line item taxable? Default is Y.

Hooks
The Form Data can be modified by using the gform_authorizenet_form_data filter.

The Form Editor

The Form Editor

OverviewTop BarThe Field LibraryThe Layout Space

Overview

The Form Editor is where most of your design and layout effort for your will be spent. Our editor layout is designed with a similar look and feel to the Block Editor in WordPress, so it should be pretty intuitive. But if this is your first steps with WordPress, or you are transitioning from a different form editor, then below you can find a quick overview of each of the areas of the form editor screen.

Top Bar

The top horizontal bar of the Gravity Forms Form Editor offers the following options:

Shows you the form you are editing, and allows you to quickly switch to other forms.Go to Form Settings.Go to this form』s Entries list.Show a preview off this form.Update the form and capture the changes you have made.

The Field Library

The right hand side of the Form Editor screen is where you can find the library of all available fields that can be added to your form.

The search bar allows you to quickly find any field.Two tabs are offered to this section, Here the Add Fields tab is selected, which shows all the available field categories.This tab gives you access to the field settings of the selected field, and will auto-select when you are select a field.All the available fields are shown here, grouped under multiple field type categories. Choose the category you are interested in, and it will expand to reveal all the available field of that category.

The following categories of fields are usually available here:

Standard Fields: the simple basics.Advanced Fields: multi-part and more complex fields.Post Fields: fields associated with WordPress posts, such as tags and excerpts.Pricing Fields: product related fields.More field categories may be added here by other add-ons.

The Layout Space

The main area of the Form Editor screen is where you arrange and tweak your fields. Drag and drop any field you like from the library onto the layout space. Here you can change settings, set the layout order, and even create columns.

Here is a quick animation to show you how fast your form can be pulled together.

< previous article next article: Fields >

Fields Available for Forms

Fields Available for Forms

IntroductionStandard FieldsAdvanced FieldsPost FieldsPricing Fields

Introduction

The Form Editor toolbox groups fields under a few categories: Standard, Advanced and Post. This post is a quick reference to all the standard field types available in Gravity Forms. 

Some fields may require a specific Gravity Forms Add-On to be installed in order to function, and that may require a certain Gravity Forms license type. Those fields are marked with an 「AO」 superscript below.

Deleting a field will also delete all entry data associated with that form field.

Standard Fields

Standard Fields are basic form fields that can be customized for just about any use. These can be used to capture and store a variety of data when an advanced field is not available to meet your needs.

Single Line TextParagraph TextDrop DownNumberCheckboxesRadio ButtonsHiddenHTMLSection BreakPage Break

Advanced Fields

Advanced Fields are more advanced form field types with specific usage in mind. Advanced fields may actually contain multiple fields in one container. These fields make it easy to capture data such as a users Name, Address, etc.

NameDateTimePhoneAddressWebsiteUsername AOPassword AOEmailFile UploadCAPTCHAListMulti SelectConsentChained Selects AOQuiz AOSurvey AO

Post Fields

Post Fields are form fields that enable you to capture data that is then used to create a WordPress Post. These fields make it quick and easy for you to create forms that allow users to submit content to your site. The result posts will be set as a Draft and will need to be published before they are visible.

Post TitlePost BodyPost ExcerptPost TagsPost CategoryPost ImagePost Custom Field

Pricing Fields

Pricing Fields are form fields that enable you to create products focussed forms. Additionally, this is where you will find Add-On specific payment collection fields, such as the Stripe Card field, and the (mostly deprectaed) generic credit card field that is still utilized for the Authorize.net Add-On.

ProductOptionQuantityShippingTotal2Checkout card field AOMollie card field AOSquare card field AOStripe card field AOCredit Card

Form Footer CSS Selectors

Form Footer CSS Selectors

ContainerSubmit ButtonSubmit Button (image)

Container
Contains the submit button and admin edit link

example: the form footer section (div) – applies to all forms
body .gform_wrapper .gform_footer {border: 1px solid red}

example: the form footer section (div) – applies just to form ID #1
body #gform_wrapper_1 .gform_footer {border: 1px solid red}

Submit Button

example: the form submit button (input) – applies to all forms
body .gform_wrapper .gform_footer input[type=submit] {border: 1px solid red}

example: the form submit button (input) – applies just to form ID #1
body #gform_wrapper_1 .gform_footer input[type=submit] {border: 1px solid red}

Submit Button (image)

example: the form submit button (image) – applies to all forms
body .gform_wrapper .gform_footer input[type=image] {border: 1px solid red}

example: the form submit button (image) – applies just to form ID #1
body #gform_wrapper_1 .gform_footer input[type=image] {border: 1px solid red}

Form Heading CSS Selectors

Form Heading CSS Selectors

ContainerTitleDescription

Container
Contains the form title and description

example: the form heading section (div) – applies to all forms
1body .gform_wrapper .gform_heading { border: 1px solid red }

example: the form heading section (div) – applies just to form ID #1
1body #gform_wrapper_1 .gform_heading { border: 1px solid red }

Title

example: the form title (h3) – applies to all forms
1body .gform_wrapper .gform_heading .gform_title { color: red }

example: the form title (h3) – applies just to form ID #1
1body #gform_wrapper_1 .gform_heading .gform_title { color: red }

Description

example: the form description (span) – applies to all forms
1body .gform_wrapper .gform_heading .gform_description { border: 1px solid red }

example: the form description (span) – applies just to form ID #1
1body #gform_wrapper_1 .gform_heading .gform_description { border: 1px solid red }

Dynamic Field Map Field

Dynamic Field Map Field

IntroductionParametersExampleValidationHelpersget_dynamic_field_map_fields()Uses

Introduction

The dynamic_field_map type field, part of the Settings API, allows the user to map their form fields to custom keys (fields), e.g. fields you will be sending to a third-party service such as a CRM.

Parameters

name string Required. Name of the field. Use it to retrieve saved data.label string Required. Field label. Will be displayed in the UItype string Required. Field type. Must be set to dynamic_field_map for the Dynamic Field Map field.tooltip string Optional. Defaults to blank (no tooltip). Displays a question mark icon and a tooltip next to the field label.field_types arrayOptional. Defaults to empty (no filtering). Array of form field types to be available as options when mapping to this field. Only form fields of the specified types will be included in the list of fields.Example: array( 『text』, 『name』 )exclude_field_types arrayOptional. Defaults to empty (no filtering). Array of form field types to be excluded when mapping to this field.Example: array( 『creditcard』 )field_map arrayOptional. Defaults to empty.By default, the Dynamic Field Map allows users to enter a custom key and map that key to a form field (using the associated form field drop down).The field_map property allows the Key field to be presented as a drop down list, where users can select from a set of predefined choices.Each item in the field_map array has the following propertieslabel stringRequired. Choice label to be displayed in the key drop down.value stringOptional. Defaults to the Label value. Value that will be saved.

choices arrayOptional. Defaults to empty.Creates an option group in the drop down. The label property becomes the Option Group label and the choices defined here become the options under the new group.Each item in the choices array has the following propertieslabel stringRequired. Choice label that is displayed in the drop down.value stringOptional. Defaults to the Label text. Value that is saved.limit int Optional. Defaults to no limit. Defines the number of fields that can be mapped by the user.enable_custom_key boolOptional. Defaults to false. Possible values are true or false. When set to true, allows users to enter a custom value in addition to the options in the drop down field.validation_callback (function)Optional. Defaults to nothing (no callback). Calls a function during validation allow for custom validation logic. The example in the existing documentation page is good.allow_duplicate boolOptional. Defaults to false. Controls whether or not the same option in the key field can be mapped multiple times.Note: This only prevents options from being selected multiple times in the drop down. If custom keys are enabled, users won』t be prevented from typing the same custom option multiple times.

Example

The following example shows how you can allow the user to define a number of custom keys and map them to their form fields, which in this case is limited to twenty. We are also excluding the creditcard field from the drop downs which contain the form fields as choices.

array(
'title' => esc_html__( 'This is the title for Section 1', 'sometextdomain' ),
'fields' => array(
array(
'name' => 'metaData',
'label' => esc_html__( 'Metadata', 'sometextdomain' ),
'type' => 'dynamic_field_map',
'limit' => 20,
'exclude_field_types' => 'creditcard',
'tooltip' => '

' . esc_html__( 'Metadata', 'sometextdomain' ) . '

' . esc_html__( 'You may send custom meta information to [...]. A maximum of 20 custom keys may be sent. The key name must be 40 characters or less, and the mapped data will be truncated to 500 characters per requirements by [...]. ', 'sometextdomain' ),
'validation_callback' => array( $this, 'validate_custom_meta' ),
),
),
),

The above code would render a field like the following:

Validation

In the above example a validation callback is also specified to ensure that the limit is not exceeded and that the custom keys don』t exceed the character limit defined by the third-party service.

public function validate_custom_meta( $field ) {
//Number of keys is limited to 20 - interface should control this, validating just in case
//key names can only be max of 40 characters

$settings = $this->get_posted_settings();
$metaData = $settings['metaData'];

if ( empty( $metaData ) ) {
return;
}

//check the number of items in metadata array
$metaCount = count( $metaData );
if ( $metaCount > 20 ) {
$this->set_field_error( array( esc_html__( 'You may only have 20 custom keys.' ), 'sometextdomain' ) );

return;
}

//loop through metaData and check the key name length (custom_key)
foreach ( $metaData as $meta ) {
if ( empty( $meta['custom_key'] ) && ! empty( $meta['value'] ) ) {
$this->set_field_error( array( 'name' => 'metaData' ), esc_html__( "A field has been mapped to a custom key without a name. Please enter a name for the custom key, remove the metadata item, or return the corresponding drop down to 'Select a Field'.", 'sometextdomain' ) );
break;
} elseif ( strlen( $meta['custom_key'] ) > 40 ) {
$this->set_field_error( array( 'name' => 'metaData' ), sprintf( esc_html__( 'The name of custom key %s is too long. Please shorten this to 40 characters or less.', 'sometextdomain' ), $meta['custom_key'] ) );
break;
}
}
}

Helpers

The following functions may come in helpful when interacting with the dynamic_field_map field type during feed processing.

get_dynamic_field_map_fields()

Retrieves the individual field_map fields from the meta property of the Feed Object for the supplied field name.

$metaData = $this->get_dynamic_field_map_fields( $feed, 'metaData' );

$feed Feed Object
The Entry Object to be checked.

$name string
The name property of the dynamic_field_map field to retrieve the mapped fields for.

Returns array
An array containing the field names or custom keys as the keys to the mapped form field ID or entry meta key.

Uses

settings_dynamic_field_map()

Dynamically Populating Drop Down, Radio Buttons or Multi-Select Fields

Dynamically Populating Drop Down, Radio Buttons or Multi-Select Fields

IntroductionThird Party OptionsCustom Code ApproachThe CodeThe HooksCustom Filter FunctionLooping Through the FieldsGet the PostsCreating an Array of ChoicesAdd a Placeholder ChoiceWhat about Checkboxes?Conclusion

Introduction

Being able to dynamically populate the values in a select (aka drop down) field is fairly common requirement for product selection forms, product option forms, or any form that requires earlier submissions to drive choices in a latter collection field.

This walkthrough will teach you how to configure a specific example of this population, using custom code to present a list of existing posts as options in the drop down.

Third Party Options

If you are not keen on custom code, or require more complex capabilities, check for third party solutions across popular WordPress Plug-In repositories, and in our very own Community Add-On Library.

Make sure you don』t miss the Add-On Populate Anything, a fully-featured offering from one of our Certified Developers, GravityWiz.

Custom Code Approach

The premise for this walkthrough is that we want to populate the options in a Gravity Form select field with all of the posts currently published on the site. There are a variety of reasons for wanting to do this, but in this example, we just want to know what the user』s favorite post is.

IMPORTANT: For obvious reasons, dynamic population can』t run when the page where your form is embedded is cached. This is not a Gravity Forms limitation but a consequence of using caching.

The Code

123456789101112131415161718192021222324252627282930add_filter( 'gform_pre_render_51', 'populate_posts' );add_filter( 'gform_pre_validation_51', 'populate_posts' );add_filter( 'gform_pre_submission_filter_51', 'populate_posts' );add_filter( 'gform_admin_pre_render_51', 'populate_posts' );function populate_posts( $form ) {     foreach ( $form['fields'] as &$field ) {         if ( $field->type != 'select' || strpos( $field->cssClass, 'populate-posts' ) === false ) {            continue;        }         // you can add additional parameters here to alter the posts that are retrieved        // more info: http://codex.wordpress.org/Template_Tags/get_posts        $posts = get_posts( 'numberposts=-1&post_status=publish' );         $choices = array();         foreach ( $posts as $post ) {            $choices[] = array( 'text' => $post->post_title, 'value' => $post->post_title );        }         // update 'Select a Post' to whatever you'd like the instructive option to be        $field->placeholder = 'Select a Post';        $field->choices = $choices;     }     return $form;}

This code should be pasted in your theme』s functions.php file.

The Hooks

Using the gform_pre_render filter allows us to modify the form right before it is displayed. This is really useful, especially when you are looking to display content that will be constantly changing. In our case, this saves us the time and hassle of having to update our drop down of posts every time we add a new post. In addition you should use the gform_pre_validation, gform_pre_submission_filter and gform_admin_pre_render filters as well.

1234add_filter( 'gform_pre_render_51', 'populate_posts' );add_filter( 'gform_pre_validation_51', 'populate_posts' );add_filter( 'gform_pre_submission_filter_51', 'populate_posts' );add_filter( 'gform_admin_pre_render_51', 'populate_posts' );

This line tells Gravity Forms to filter the $form object through the populate_posts function every time the form with ID of 51 is displayed. You should update the 51 here to the ID of your form.

Please note: A form-specific version of the gform_pre_validation filter was added in Gravity Forms version 1.9.

Next, let』s create a populate_posts function to modify our form.

Custom Filter Function

In this example, our custom filter function is titled 「populate_posts」. Since we told Gravity Forms to call this function from the gform_pre_render filter, Gravity Forms will also send the $form object as a parameter to this function. This means we can modify the $form object with this function and then return our changes at the end of the function.

Looping Through the Fields

1foreach ( $form['fields'] as $field ) { ... }

Since we have the $form object, let』s loop through the fields in the form and find the field(s) that we』d like to modify.

123if ( $field->type != 'select' || strpos( $field->cssClass, 'populate-posts' ) === false ) {    continue;}

Given our premise, we only want to modify fields that are select (drop down) fields AND have a CSS class titled 「populate-posts」. We could check for the field ID instead of a CSS class; however, if we ever change our form we』d have to update the code to match the new field ID. Using a CSS class to identify our desired field allows us to manage which field should be targeted right from the Gravity Forms admin.

If the current field we are at in the loop is not a select OR does not have our designated CSS class, we simply skip that field and move on to the next.

Get the Posts

Now it』s time to get an array of all the posts to display in our drop down.

1$posts = get_posts( 'numberposts=-1' );

get_posts() is a WordPress function that returns an array of posts based on the parameters you provide it. For more information on how to modify which posts are returned, read here.

Quick Tip: You can retrieve any kind of post type here; even custom post types. Just pass the name of your post type with the 「post_type」 parameter:

1$posts = get_posts( 'post_type=event&numberposts=-1' );

Creating an Array of Choices

The way Gravity Forms handles fields with multiple options (such as a select field) is with a 「choices」 property for the field which contains an array of 「options」. Each option consists of:

a 「text」 property (which is what the user will see in the drop down)a 「value」 property (which is what will be recorded by Gravity Forms)an 「isSelected」 property (which is used to indicate whether the option is currently selected or not)and a 「price」 property (which only applies to pricing fields)

In our scenario, we are only concerned with the 「text」 and 「value」 properties.

1$choices = array();

The first thing we do is create an array to store all of our options.

123foreach ( $posts as $post ) {    $choices[] = array( 'text' => $post->post_title, 'value' => $post->post_title );}

Next, we』re going to loop through the posts we retrieved using the get_posts() function and create an option array for each post. For the 「text」 property we will use the Post Title and for the 「value」 property we will use the same. In some cases you may want to collect the ID of the selected post. If so you』d use $post->ID instead of $post->post_title; however, for our goal of recording the users favorite post, the post title is sufficient.

1$field->choices = $choices;

Once we』ve looped through all of the posts and created all of our options, we assign the $choices array (which has all of our new options) to the $field choices property.

Add a Placeholder Choice

1$field->placeholder = 'Select a Post';

We also want to make the first option in the drop down a 「placeholder」 choice. It let』s the user know what they are supposed to do with this drop down (ie 「Select a Post」). We do this by assigning the choice text to the fields placeholder property.

When the drop down is rendered on the form the placeholder choice will have an empty value for the 「value」 property. This ensures that if this is a required field, that the user must select an option other than the placeholder option. Failing to do so will generate a validation error.

What about Checkboxes?

Checkbox fields can also be dynamically populated, but they require additional handling since their structure is created by a fieldset of inputs and choices. See this example code for Dynamically Populating a Checkbox as included in our gform_pre_render documentation.

Conclusion

That』s all there is to it! When you view your form on the front end you should now see that your select field is populated with a list of all your current posts.

Dynamically Populating the Post Author

Dynamically Populating the Post Author

Registering a Function to a HookGetting and Returning the ValueUsing 『Admin Only』 FieldsConclusion

If you aren』t familiar with dynamic population with Gravity Forms, it is probably worth your while to take a quick breeze through the Using Dynamic Population walk-through.
This walk-through demonstrates how to retrieve the author』s email based on the post that the Gravity Form is being displayed.
Let』s jump right into the code!
add_filter( 'gform_field_value_author_email', 'populate_post_author_email' );
function populate_post_author_email( $value ) {
global $post;

$author_email = get_the_author_meta( 'email', $post->post_author );

return $author_email;
}

The first thing you would do with this code is copy and paste it into your theme』s functions.php file. Now let』s break it down line by line to get a better understanding of what is happening.
Registering a Function to a Hook
add_filter( 'gform_field_value_author_email', 'populate_post_author_email' );

With this line, we are registering a custom function populate_post_author_email to the gform_field_value_parameter_name filter. All this means is when Gravity Forms is rendering the form on a page it will call our custom populate_post_author_email function *and then* populate the value returned by our custom function into the field.
So how does Gravity Forms know which field to populate with the returned value? The dynamic population parameter! Note that you can apply the same parameter name to as many fields as you』d like and this code would populate them all.
Ready for the next bit of code?
Getting and Returning the Value
The next step is getting the value we want to populate into the field and then returning it so Gravity Forms can populate our field.
global $post;

$author_email = get_the_author_meta( 'email', $post->post_author );

return $author_email;

In this example, we want to get the author』s email based on the post that the Gravity Form is embedded in. To get access to all the juicy post details, we need to declare the $post object global. We can now access various properties of the current post.
One of those properties is the post_author which is the ID of the current post』s author. Why do we need this? To get the author』s email of course! We』ll pass the author』s ID and the author meta (aka 』email』) we are looking for to the WordPress get_the_author_meta function. This function will then return the… you guessed it, author email.
Now all we have to do is return the author』s email back to Gravity Forms which will automatically populate our field with the returned value.
Using 『Admin Only』 Fields
We』ve got our field populating with the post author』s email perfectly… but then you do your first test submission and realize that the author』s email is included in the {all_fields} token when the email notification is generated. You』d prefer that this field only be visible to the admin. What do you do?
You set the field』s visibility to Administrative and update the merge tag to {all_fields:noadmin}. This will prevent the field from displaying in the default notification emails. If the field has dynamic population enabled, this field will display as a hidden field when the form is displayed. If dynamic population is not enabled, the field will not display at all.
Conclusion
Let us know if you have any questions on this or suggestions to better explain this functionality.