This article contains PHP examples and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.
Below are some commonly requested customizations that require PHP. You can add these code samples to a new plugin or your theme functions.php at the very bottom, before the last ?> if there is one.
Entries
Get multiple entries
$entries = FrmEntry::getAll(array('it.form_id' => 5), ' ORDER BY it.created_at DESC', 8);
Create an entry with PHP
This is advanced, and should only be used by those experienced with PHP. This function inserts entries in the database. It sanitizes variables, does some checks, fills in missing variables like date/time, etc. When this snippet is used, Form Actions associated with the form will also run. It takes an array as its argument and returns the entry ID of the created entry (or 0 if there is an error).
<?php global $user_ID; FrmEntry::create(array( 'form_id' => 5, //change 5 to your form id 'item_key' => 'entry', //change entry to a dynamic value if you would like 'frm_user_id' => $user_ID, //change $user_ID to the id of the user of your choice (optional) 'item_meta' => array( 25 => 'value', //change 25 to your field ID and 'value' to your value 26 => 'value', 27 => 'value', //add any field ids here with the value to insert into it ), )); ?>
If you'd like the entry to go through validation first, you can create the entry this way instead:
$entry = array( 'form_id' => 5, //change 5 to your form id 'item_key' => 'entry', //change entry to a dynamic value if you would like 'frm_user_id' => $user_ID, //change $user_ID to the id of the user of your choice (optional) 'item_meta' => array( 25 => 'value', //change 25 to your field ID and 'value' to your value 26 => 'value', 27 => 'value', //add any field ids here with the value to insert into it ); $_POST = $entry; $errors = FrmEntryValidate::validate( $_POST ); FrmEntry::create( $_POST );
If this is also a User Registration form, and you would like users to be created, the form settings may need some adjustment. Check the box to "Allow logged-in users to create new users with this form" to trigger the new user creation. The role needed will be based on whoever is logged in when the code snippet is run.
Create a file with PHP
In this basic PHP example, you can add an entry to a form with only a file upload field. It is necessary to provide three variables: file path, file upload field ID, and the form ID. Note that a file upload field requires an attachment ID as input.
$path = '...'; // Change this to the full file path we're adding to our file field. $file_field_id = 24154; // Change this. $form_id = 1729; // Change this. $attachment_data = array( 'post_mime_type' => 'image/jpeg', 'post_status' => 'publish', ); $new_attachment_id = wp_insert_attachment( $attachment_data, $path ); // Generate the metadata for the attachment, and update the database record. require_once ABSPATH . 'wp-admin/includes/image.php'; wp_generate_attachment_metadata( $new_attachment_id, $path ); $entry_data = array( 'form_id' => $form_id, 'item_key' => 'entry', 'item_meta' => array( $file_field_id => $new_attachment_id, ), ); FrmEntry::create( $entry_data );
Duplicate an entry
If your users are allowed to edit their own entries, you can allow them to create a duplicate of any entry on the front-end of your site.
Insert the following shortcode on a page where you would like the form to be shown in edit mode with the duplicated entry: [duplicate_entry_form id=5 entry_id=duplicate_id field_id=25]
Change 5 to the form id and 25 to the id of the user ID field in that form. entry_id can be the id of the entry to duplicate, or a name to find in the url like ?duplicate=40. It typically works best to create a View that lists entries, then include a link like this in your View Content:
<a href="url-of-page-with-shortcode/?duplicate_id=[id]&user_id=[406 show=ID]">Duplicate</a>
Replace 406 with the ID of the userID field in your form. Replace url-of-page-with-shortcode with the URL of the page where the [duplicate_entry] shortcode is placed.
add_shortcode( 'duplicate_entry_form', 'frm_duplicate_entry_form' ); function frm_duplicate_entry_form( $atts ) { $old_id = $atts['entry_id']; if ( ! empty( $old_id ) && ! is_numeric( $old_id ) ) { $old_id = absint( $_GET[ $old_id ] ); } $user_id_field = absint( $atts['field_id'] ); /* add_filter( 'frm_add_entry_meta', 'autoincrement_on_duplicate' );*/ //Un-comment this line if you have auto increment field in your form $new_entry_id = FrmEntry::duplicate( $old_id ); /* remove_filter( 'frm_add_entry_meta', 'autoincrement_on_duplicate' );*/ //Un-comment this line if you have auto increment field in your form // set the new entry to the ID of the current user global $wpdb; $wpdb->update( $wpdb->prefix .'frm_items', array( 'user_id' => get_current_user_id() ), array( 'id' => $new_entry_id ) ); $wpdb->update( $wpdb->prefix .'frm_item_metas', array( 'meta_value' => get_current_user_id() ), array( 'item_id' => $new_entry_id, 'field_id' => $user_id_field ) ); return FrmFormsController::get_form_shortcode( array('id' => $atts['id'], 'entry_id' => $new_entry_id ) ); } // Un-comment the function below if you have an auto-increment field in your form /*function autoincrement_on_duplicate( $values ) { $field_id = 7933; //Replace 7933 with the ID of your Auto increment field if ( $field_id === (int) $values['field_id'] ) { $field = FrmField::getOne( $field_id ); $value = $field->default_value; FrmProFieldsHelper::replace_non_standard_formidable_shortcodes( array( 'field' => $field ), $value ); $values['meta_value'] = $value; } return $values; }*/
Delete an entry
Add this inside your function and make sure $entry_id is replaced with the entry you would like to delete.
FrmEntry::destroy( $entry_id );
Delete User entries when a User is deleted
Automatically delete entries from a form when a user account is deleted from your WordPress site.
add_action( 'delete_user', 'my_delete_user' ); function my_delete_user( $user_id ) { global $wpdb; $form_id = 19; //change 19 to the id of the form you would like to delete entries from $user_entry = $wpdb->get_col( $wpdb->prepare("SELECT id FROM ". $wpdb->prefix ."frm_items WHERE user_id = %d AND form_id = %d", $user_id, $form_id) ); foreach ( $user_entry as $value ) { FrmEntry::destroy( $value ); } }
Update a field value
When a field is used in a post, use the WordPress functions like update_post_meta or wp_update_post.
$field_id = 123; $entry_id = 25; $new_value = 'Value here'; $updated = FrmEntryMeta::update_entry_meta( $entry_id, $field_id, null, $new_value ); if ( ! $updated ) { FrmEntryMeta::add_entry_meta( $entry_id, $field_id, null, $new_value ); }
Get entry id from post id
$entry_id = FrmDb::get_var( 'frm_items', array( 'post_id' => $post_id_here ), 'id' );
Get form id from entry id
$entry = FrmEntry::getOne( $entry_id ); $form_id = $entry->form_id;
Fields
Get field ID from Key
$field_id = FrmField::get_id_by_key('keyhere');
Get field Key from ID
$field_key = FrmField::get_key_by_id( 5 );
Display a Field Description
Do you want to display a field description in a view or email? The content of an HTML field is also saved as a field description. Use this shortcode on a page, View, etc. [frm-show-description field_id=x]
add_shortcode( 'frm-show-description', 'frm_show_description' ); function frm_show_description( $atts ) { if ( ! isset( $atts['field_id'] ) || ! is_numeric( $atts['field_id'] ) ) { return ''; } $field_info = FrmField::getOne( $atts['field_id'] ); return $field_info->description; }
Views
Compare two fields in View
Use this shortcode to compare two fields in your View.
add_shortcode('compare', 'compare_func'); function compare_func($atts, $content=""){ extract(shortcode_atts(array('val1' => '', 'val2' => '', 'type' => '=='), $atts)); if ( $type == 'greater_than' ) { $type = '>'; } else if ( $type == 'less_than' ) { $type = '<'; } else if ( $type == 'equals' ) { $type = '=='; } if ( !FrmFieldsHelper::value_meets_condition($val1, $type, $val2) ) { $content = ''; } return $content; }
Usage:
[compare val1="[x]" type="==" val2="[y]"]content here[/compare]
Replace x and y with your field ids and replace == with your condition. If you would like to check if the two values are equal, use ==. You can also use type="greater_than", less_than, or equals.
Calculate a Total in View
After adding this code to your theme functions.php or a new plugin, you can easily calculate the sum of any number of fields inside of a View using this shortcode: [sum vals="[125],[126],[127]"]. Replace 125, 126, and 127 with field IDs from your form. Please note, this is only meant to be used to add fields. This cannot be used to subtract, multiply, or divide fields without further customization.
add_shortcode('sum','my_entry_count'); function my_entry_count($atts){ extract( shortcode_atts(array( 'vals' => '0', ), $atts ) ); $val_array = explode(',', $vals); $total = array_sum($val_array); return $total; }
Forms
Use pre 3.0 theme preview
Version 3.0+ uses an auto generated page from your theme. If you need the old page to continue function, add this function to your site.
add_filter( 'the_content', 'page_route', 10 ); function page_route( $content ) { global $post; $preview_page_id = 25; // change 25 to the ID of your form preview page if ( $post && $post->ID == $preview_page_id && isset( $_GET['form'] ) ) { $content = FrmFormsController::page_preview(); } return $content; }
Use the old preview links
—This PHP example is no longer supported for integration reasons. —
Get form ID by key
$form_id = FrmForm::get_id_by_key('keyhere');
Admin area
Expand the WordPress menu sidebar
Formidable will use the full screen mode set in the block builder. This code will always show the WordPress Menu when editing Forms and Views.
add_filter( 'frm_admin_full_screen_class', 'frm_keep_full_screen' ); function frm_keep_full_screen(){ return ''; }
Remove the SMTP menu
This code will remove the SMTP option from the Formidable menu.
add_action( 'admin_menu', 'frm_remove_smtp_menu', 9999); function frm_remove_smtp_menu() { remove_submenu_page( 'formidable', 'formidable-smtp' ); }
Bulk Delete Formidable log entries
This code will delete 500 log entries every time your page is loaded
add_action( 'plugins_loaded', 'delete_formidable_logs' ); function delete_formidable_logs() { $mycustomposts = get_posts( array( 'post_type' => 'frm_logs', 'numberposts' => 500)); foreach( $mycustomposts as $mypost ) { wp_delete_post( $mypost->ID, true); } }
Prevent WordPress from loading jQuery migrate
jQuery migrate is a file that gets loaded automatically with WordPress. It's used to help transition from old versions of jQuery to a newer version. It's useful for testing but shouldn't be necessary for a form to work. Use this code snippet to prevent jQuery migrate from loading on the front end, and from the Formidable preview page.
function remove_jquery_migrate( $scripts ) { $should_remove_jquery_migrate = ! is_admin() || FrmAppHelper::is_preview_page(); if ( isset( $scripts->registered['jquery'] ) && $should_remove_jquery_migrate ) { $script = $scripts->registered['jquery']; if ( $script->deps ) { // Check whether the script has any dependencies $script->deps = array_diff( $script->deps, array( 'jquery-migrate' ) ); } } } add_action( 'wp_default_scripts', 'remove_jquery_migrate' );
Disable the summary email
Use this code snippet to disable the summary emails configured in the Global settings.
add_action( 'init', function() { $settings = FrmAppHelper::get_settings(); $settings->summary_emails = 0; } );
Shortcodes
Get the most selected field value
Get the most selected field value from a specific field. Put [frm-most-selected id=x] on a page, form, View, etc. Replace x with the ID of a field.
add_shortcode( 'frm-most-selected', 'frm_most_selected_value' ); function frm_most_selected_value( $atts ){ if ( ! isset( $atts['id'] ) || ! is_numeric( $atts['id'] ) ) { return ''; } $field = FrmField::getOne( $atts['id'] ); $meta_values = FrmProEntryMeta::get_all_metas_for_field( $field ); // Flatten and unserialize meta values $final_values = array(); foreach ( $meta_values as $meta_val ) { $meta_val = maybe_unserialize( $meta_val ); if ( is_array( $meta_val ) ) { $final_values = array_merge( $final_values, $meta_val ); } else { $final_values[] = $meta_val; } } // Get most popular $count_values = array_count_values( $final_values ); arsort( $count_values ); $popular = array_slice( array_keys( $count_values ), 0, 1, true ); $popular = reset( $popular ); // Get display value $popular = FrmProEntriesController::filter_display_value( $popular, $field ); return $popular; }
Check parameter value
Use the following code to check if a parameter has a specific value set. Use [if_get_param name="param_name_goes_here" type="equals" value="put_value_here"]Your content[/if_get_param] to show content only if the retrieved value matches the value set in your shortcode.
add_shortcode('if_get_param', 'check_get_param_value'); function check_get_param_value( $atts, $content="" ) { if ( ! isset( $atts['name'] ) || ! isset( $atts['value'] ) || ! isset( $atts['type'] ) ) { return $content; } $type = $atts['type']; if ( $type == 'greater_than' ) { $type = '>'; } else if ( $type == 'less_than' ) { $type = '<'; } else if ( $type == 'equals' ) { $type = '=='; } else if ( $type == 'not_equal' ) { $type = '!='; } $get_value = isset( $_GET[ $atts['name'] ] ) ? $_GET[ $atts['name'] ] : ''; if ( ! FrmFieldsHelper::value_meets_condition( $get_value, $type, $atts['value'] ) ) { $content = ''; } return do_shortcode( $content ); }
Show parameter value on a page
Use the following code to show the value of a URL parameter on a WordPress page or post.
Usage: [show_param param="color"]
Note: [get param="param-name"] works in forms, Views, and other Formidable contexts. [show_param] would only be needed in non-Formidable contexts, like WordPress pages and posts.
add_shortcode('show_param', 'ff_show_param'); function ff_show_param( $atts ) { if ( ! isset( $atts['param'] ) ) { return ""; } $get_value = isset( $_GET[ $atts['param'] ] ) ? $_GET[ $atts['param'] ] : ''; $get_value = utf8_decode( urldecode( $get_value ) ); return esc_html( $get_value ); }
Show content based on current user's role
The following shortcode, when used with frm-condition, can show content conditionally based on the current user's role. The [has_role] shortcode will return 1 if the current user has the WordPress capability set in the "cap" param and 0 if the user does not. By default, the shortcode checks if the user is an admin, but any WordPress capability can be used to check for any WordPress role you'd like. Please see the Codex on WordPress roles and capabilities for more information.
Usage:
[frm-condition source=has_role equals=1]content for admins[/frm-condition]
[frm-condition source=has_role equals=0]content for non-admins[/frm-condition]
[frm-condition source=has_role cap="read_private_pages" equals=1]content for editors and higher[/frm-condition]
add_shortcode( 'has_role', 'ff_has_role' ); function ff_has_role( $atts ) { $atts = shortcode_atts( array( 'cap' => 'activate_plugins', ), $atts, 'has_role' ); return current_user_can( $atts['cap'] ) ? 1 : 0; }
Show content if current user is logged in
The following shortcode, when used with frm-condition, can show content only to logged-in users or only to visitors who aren't logged in. The [is_logged_in] shortcode will return 1 if the current user is logged in and 0 if not.
Usage:
[frm-condition source=is_logged_in equals=1]content for logged-in users[/frm-condition]
[frm-condition source=is_logged_in equals=0]content for visitors who aren't logged in[/frm-condition]
add_shortcode( 'is_logged_in', 'ff_is_logged_in' ); function ff_is_logged_in () { return is_user_logged_in() ? 1 : 0; }
Show content based on the current month
The following shortcode, when used with frm-condition, can show content based on the month in which the page, post, View, etc. is being viewed. The [current_month] shortcode will return the number of the current month, using typical month numbering, where January is 1 and December is 12.
Usage:
[frm-condition source=current_month equals=1]content you want users to see in January[/frm-condition]
[frm-condition source=current_month greater_than=6]content you want users to see in July through December[/frm-condition]
add_shortcode( 'current_month', 'ff_current_month' ); function ff_current_month() { return date( 'n' ); }
Get current page's slug
Use the following shortcode to display the slug of the current page/post/custom post type. If you'd like to show the slug of another page/post/CPT, you can use the post_id param with the post id of that page/post/CPT.
Note: The page/post/CPT must be published to have a slug. If the page/post/CPT has a status of "pending," the slug will be blank.
Usage:
[page_slug] - displays current page's slug
[page_slug post_id=12] -- displays slug of page
[page_slug post_id=[post_id]] -- displays the slug of the current entry's page/post/CPT slug in a View
function get_page_slug( $atts ){ if ( ! empty( $atts['post_id'] ) ) { return get_post_field( 'post_name', ( int ) $atts['post_id'] ); } return get_post_field( 'post_name'); } add_shortcode( 'page_slug', 'get_page_slug' );
Show shortcode for a specified date range
You can use this shortcode to show a particular form, View, or other shortcode only during a specific date range. Before the beginning of the date range, you can display a message, if you like. After that date, you can display a different message, if you like.
- Use double quotes for the params in the [show-in-date-range] shortcode.
- Set the shortcode param to the shortcode you want to use, without the brackets. Use single quotes for params within the shortcode param.
- Set the start and end params to valid date strings that work with strtotime. If you don't want a start or an end date, you can omit the corresponding param.
- Set the early-msg and late-msg params to the messages you want to show the user before and after the date range.
Usage:
[show-in-date-range shortcode="formidable id='60' title='1' color='red' book='Pride & Prejudice'" start="November 1, 2018" end="November 30, 2018" early-msg="Signups for the dinner will begin November 1." late-msg="Sorry! It's too late to sign up for this year's dinner. We'd love to have you join us next year."]
Note: form scheduling is a built-in feature, so there's no need to use the [show-in-date-range] shortcode to schedule an entire form. You could use [show-in-date-range] with a form if, for example, you wanted to have multiple instances of the same form for different events, each with a different date range.
add_shortcode( 'show-in-date-range', 'ff_show_in_date_range' ); function ff_show_in_date_range( $atts ) { if ( empty( $atts['shortcode'] ) ) { return 'No shortcode was entered.'; } if ( ! empty ( $atts['start'] ) ) { $start = strtotime( $atts['start'] ); if ( ! $start ) { return 'Start date is not a valid date.'; } if ( time() < $start ) { return $atts['early-msg'] ? $atts['early-msg'] : ''; } } if ( ! empty ( $atts['end'] ) ) { $end = strtotime( $atts['end'] ); if ( ! $end ) { return 'End date is not a valid date.'; } if ( time() > $end ) { return $atts['late-msg'] ? $atts['late-msg'] : ''; } } return do_shortcode( '[' . $atts['shortcode'] . ']' ); }
Show display names from a list of user ids
You can use the [user_info] shortcode to show the corresponding display names (or other user data) of a comma-separated list of user ids or a single user id.
Parameters:
- users: a comma-separated list of user ids. In a View, the list can be taken from a field.
- data: the user data you want to display. Default: display_name. You can see a list of some useful options at the bottom of this page in the WordPress docs: https://developer.wordpress.org/reference/functions/get_userdata/
- backup: if the data you want to display isn't available for a user, this backup data will be displayed instead. Default: user_login.
Usage:
[user_info users="20, 32, 41"] -- shows the display names for the listed users
[user_info users="[100]"] -- shows the display names for the users whose ids are in a comma-separated list in field 100
[user_info users="20,112,128" data="user_email" backup="user_login"] -- shows the emails of the listed users
function user_info_shortcode( $atts ) { $atts = shortcode_atts( array( 'users' => false, 'data' => 'display_name', 'backup' => 'user_login', ), $atts ); if ( ! $atts['users'] ) { return ''; } $users = explode( ',', $atts['users'] ); $users_info = array_reduce( $users, function ( $result, $current ) use ( $atts ) { $current_user = get_userdata( trim( $current ) ); if ( ! $current_user ) { return $result; } $separator = ( '' === $result ) ? '' : ', '; $data = $current_user->{$atts['data']}; if ( ! $data ) { if ( empty( $atts['backup'] ) || empty( $current_user->{$atts['backup']} ) ) { return $result; } $data = $current_user->{$atts['backup']}; if ( ! $data ) { return $result; } } return $result . $separator . $data; }, '' ); return $users_info; } add_shortcode( 'user_info', 'user_info_shortcode' );
Square root
Use the following shortcode to calculate the square root of a given number.
Usage:
[square_root number=9] -- displays 3 on the page.
[square_root number=[100]] -- in a View, displays the square root of the value in field with id 100.
function frm_square_root( $atts ) { $a = shortcode_atts( array( 'number' => '1', ), $atts ); return sqrt( $a['number'] ); } add_shortcode( 'square_root', 'frm_square_root' );
Use Formidable shortcodes
With the following shortcode, special Formidable shortcodes like [get param], [date], and [user_role] in the enclosed content will be evaluated. This shortcode enables the use of these shortcodes on a normal WordPress page or post and in other non-Formidable contexts.
Usage:
- [with-frm-shortcodes]Color is: [get param=color]. Date is [date].[/with-frm-shortcodes]
- [with-frm-shortcodes][frm-stats id=3871 type=count [if get param=color]3871=[get param=color][/if get]][/with-frm-shortcodes]
Note:
- This shortcode requires Formidable Pro to be active. Any paid license will work.
function with_frm_shortcodes_shortcode( $atts = [], $content = null, $tag = '' ) { if ( ! is_null( $content ) ) { if ( is_callable( array( 'FrmProFieldsHelper', 'replace_non_standard_formidable_shortcodes' ) ) ) { FrmProFieldsHelper::replace_non_standard_formidable_shortcodes( array(), $content ); } $content = do_shortcode( $content ); if ( is_callable( array( 'FrmAppHelper', 'kses' ) ) ) { $content = FrmAppHelper::kses( $content, 'all' ); } else { $content = wp_kses_post( $content ); } } return $content; } function with_frm_shortcodes_init() { add_shortcode( 'with-frm-shortcodes', 'with_frm_shortcodes_shortcode' ); } add_action( 'init', 'with_frm_shortcodes_init' ); add_filter( 'no_texturize_shortcodes', 'frm_shortcodes_to_exempt_from_wptexturize' ); function frm_shortcodes_to_exempt_from_wptexturize( $shortcodes ) { $shortcodes[] = 'with-frm-shortcodes'; return $shortcodes; }
Remove empty shortcode params
You can remove shortcode parameters with empty values using the [frm-remove-empty] shortcode. This can be useful when you have a shortcode like [frm-graph] or [frm-stats] that has one or more field filters that get their values from [get param]. If the parameter in [get param] doesn't have a value, the field filter is removed. This shortcode is especially powerful in combination with the [with-frm-shortcodes] shortcode.
To use the frm-remove-empty shortcode:
- Create the normal shortcode exactly as you want it, e.g. [frm-stats id=items type=total color="[get param=color]"].
- Put frm-remove-empty first and "source=" in front of the shortcode tag. Leave everything else the same. Final shortcode:
[frm-remove-empty source=frm-stats id=items type=total color="[get param=color]"]
Example using [with-frm-shortcodes]:
- [with-frm-shortcodes][frm-remove-empty source=frm-graph fields="4431" x_axis="3069" data_type="average" 3069_greater_than=[get param=startdate] 3069_less_than=[get param=enddate]][/with-frm-shortcodes]
function frm_remove_empty_shortcode( $atts = [], $content = null, $tag = '' ) { if ( ! ( is_array( $atts ) ) || empty( $atts['source'] ) ){ return ''; } $source = $atts['source']; unset( $atts['source'] ); $atts_with_values = array_filter( $atts, function( $value ) { return $value !== ''; }); $atts_string = ''; foreach ( $atts_with_values as $key=>$value ){ $atts_string .= " $key='$value'"; } $shortcode_string = "[$source $atts_string]"; if ( ! is_null( $content ) ){ $shortcode_string .= " $content [/$source]"; } $result = do_shortcode( $shortcode_string); if ( is_callable( array( 'FrmAppHelper', 'kses' ) ) ) { $result = FrmAppHelper::kses( $result, 'all' ); } else { $result = wp_kses_post( $result ); } return $result; } function frm_remove_empty_init() { add_shortcode( 'frm-remove-empty', 'frm_remove_empty_shortcode' ); } add_action( 'init', 'frm_remove_empty_init' );
Conditional statement with OR condition
Use a conditional statement with OR condition in a View, message, or confirmation.
[compare_val val1="[x]" str="Yes" val2="[y]"] There is a match[/compare_val].
Add the code below to your theme functions.php or a new plugin to check if the user selected yes in either of the fields. Replace x and y with the ID of the fields you want to compare.
add_shortcode('compare_val', 'compare_multiple'); function compare_multiple($atts, $content=""){ extract(shortcode_atts(array('val1' => '', 'val2' => '', 'str' => ''), $atts)); if($val1 == $str || $val2 == $str){ return $content; } return ''; }
Styles
Allow additional style rules
Use this code snippet to allow additional style rules that are generally deleted by kses filtering. This adds a list of style rules that will not be stripped when the style is used in a form submission, such as a rich text field.
add_filter('safe_style_css', 'add_style_rules'); function add_style_rules( $safe_style_css ) { $safe_style_css[] = 'outline'; $safe_style_css[] = '-webkit-text-size-adjust'; $safe_style_css[] = '-webkit-text-size-adjust'; $safe_style_css[] = '-ms-text-size-adjust'; $safe_style_css[] = '-moz-box-sizing'; $safe_style_css[] = '-webkit-box-sizing'; $safe_style_css[] = 'box-sizing'; return $safe_style_css; }
Cookies
Set a cookie for later use
This is commonly used when there is a value in the URL when your site is first reached. But if the form isn't submitted on that first page load, it's tricky to get those URL values into the form. The solution is to save the value to a cookie that will persist across pages.
add_action( 'init', 'set_url_cookie', 1 ); function set_url_cookie() { $cookie_name = 'frm_url_value_' . COOKIEHASH; // change frm_url_value if you would like $value_name = 'utm_source'; if ( $_GET && isset( $_GET[ $value_name ] ) ) { $expiration = 30000000; setcookie( $cookie_name, $_GET[ $value_name ], time() + $expiration, COOKIEPATH, COOKIE_DOMAIN ); } }
Get a cookie value in a field
This example creates a shortcode you can use on a page or inside of a form field. Example: [frm_referrer_cookie name="cookie_name_here"] or [frm_referrer_cookie name="frm_url_value"]
add_shortcode( 'frm_referrer_cookie', 'frm_referrer_cookie' ); function frm_referrer_cookie( $atts ) { $cookie_name = sanitize_text_field( $atts['name'] ); $value = ''; $cookie_name = $cookie_name . COOKIEHASH; if ( isset( $_COOKIE[ $cookie_name ] ) ) { $value = $_COOKIE[ $cookie_name ]; } return $value; }