Below, you’ll find a detailed guide on how to add the Fluentform Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Fluentform Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the Fluentform Plugin and the shortcodes it provides:
"Contact Form Plugin by Fluent Forms is a fast and efficient contact form builder for WordPress. It simplifies form creation and management on your website for seamless user interactions."
- [fluentform]
- [fluentform_info]
- [ff_get]
Fluentform [fluentform] Shortcode
`fluentform` is a shortcode that allows the rendering of a form on your website. It accepts various parameters like ‘id’, ‘title’, ‘css_classes’, etc. to customize the form. This shortcode checks for user permissions, and if the user doesn’t have the required permission, a message is displayed. It’s flexible and adaptable to your needs.
Shortcode: [fluentform]
Parameters
Here is a list of all possible fluentform shortcode parameters and attributes:
id
– Unique identifier of the specific form.title
– The title of the form, not visible to users.css_classes
– Add custom styles to the form using CSS classes.permission
– Defines who can view the form based on user roles.type
– Determines the form layout, ‘classic’ is the default style.permission_message
– The message displayed when a user doesn’t have the required permissions.
Examples and Usage
Basic example – The shortcode to display a form by referencing its ID.
[fluentform id=1 /]
Advanced examples
Displaying a form by referencing its ID and adding CSS classes.
[fluentform id=1 css_classes="class1 class2" /]
Displaying a form by referencing both ID and title. The form will first try to load by ID, but if not found, it will try to load by title.
[fluentform id=1 title="Contact Form" /]
Displaying a form by referencing its ID, adding CSS classes, and setting the type to ‘step’.
[fluentform id=1 css_classes="class1 class2" type="step" /]
Displaying a form by referencing its ID, adding CSS classes, setting the type to ‘step’, and defining a custom permission message.
[fluentform id=1 css_classes="class1 class2" type="step" permission_message="You are not authorized to view this form." /]
PHP Function Code
In case you have difficulties debugging what causing issues with [fluentform]
shortcode, check below the related PHP functions code.
Shortcode PHP function:
$this->app->addShortCode('fluentform', function ($atts, $content) {
$data = [
'id' => null,
'title' => null,
'css_classes' => '',
'permission' => '',
'type' => 'classic',
'permission_message' => __('Sorry, You do not have permission to view this form', 'fluentform')
];
/* This filter is deprecated, will be removed soon */
$data = apply_filters('fluentform_shortcode_defaults', $data, $atts );
$shortcodeDefaults = apply_filters('fluentform/shortcode_defaults', $data, $atts);
$atts = shortcode_atts($shortcodeDefaults, $atts);
return $this->renderForm($atts);
});
Fluentform [fluentform_info] Shortcode
The shortcode ‘fluentform_info’ is a versatile tool allowing users to retrieve various data from a form. The shortcode: [fluentform_info] It can fetch submission count, creation and update timestamps, and total payment received. It also accommodates filters for data like status, payment status, and trash status. You can customize the output with options like ‘substract_from’, ‘hide_on_zero’, and ‘currency_formatted’.
Shortcode: [fluentform_info]
Parameters
Here is a list of all possible fluentform_info shortcode parameters and attributes:
id
– Unique identifier of the form.info
– Determines the type of information to retrieve.status
– Filters the form submissions based on their status.with_trashed
– Allows inclusion of trashed submissions.substract_from
– Subtracts the total count from a specified number.hide_on_zero
– Hides the count when it is zero.payment_status
– Filters submissions based on payment status.currency_formatted
– Shows the total payment in a currency format.date_format
– Formats the date of form creation or update.
Examples and Usage
Basic example – Show the submission count of a form.
[fluentform_info id="1" info="submission_count"]
Advanced examples
Display the creation date of a form in a specific format.
[fluentform_info id="2" info="created_at" date_format="F j, Y, g:i a"]
Display the total payment received from a form, subtracting a particular amount, and hiding the result if it’s zero.
[fluentform_info id="3" info="payment_total" substract_from="500" hide_on_zero="yes" currency_formatted="yes"]
Show the submission count of a form, but only count the entries marked as “favourites” and exclude the trashed ones.
[fluentform_info id="4" info="submission_count" status="favourites" with_trashed="no"]
Display the last update date of a form in the default date format.
[fluentform_info id="5" info="updated_at"]
PHP Function Code
In case you have difficulties debugging what causing issues with [fluentform_info]
shortcode, check below the related PHP functions code.
Shortcode PHP function:
$this->app->addShortCode('fluentform_info', function ($atts) {
$data = [
'id' => null, // This is the form id
'info' => 'submission_count', // submission_count | created_at | updated_at | payment_total
'status' => 'all', // get submission cound of a particular entry status favourites | unread | read
'with_trashed' => 'no', // yes | no
'substract_from' => 0, // [fluentform_info id="2" info="submission_count" substract_from="20"]
'hide_on_zero' => 'no',
'payment_status' => 'all', // it can be all / specific payment status
'currency_formatted' => 'yes',
'date_format' => '',
];
/* This filter is deprecated, will be removed soon */
$data = apply_filters('fluentform_info_shortcode_defaults', $data, $atts );
$shortcodeDefaults = apply_filters('fluentform/info_shortcode_defaults', $data, $atts);
$atts = shortcode_atts($shortcodeDefaults, $atts);
$formId = $atts['id'];
$form = wpFluent()->table('fluentform_forms')->find($formId);
if (!$form) {
return '';
}
if ('submission_count' == $atts['info']) {
$countQuery = wpFluent()->table('fluentform_submissions')
->where('form_id', $formId);
if ('trashed' != $atts['status'] && 'no' == $atts['with_trashed']) {
$countQuery = $countQuery->where('status', '!=', 'trashed');
}
if ('all' == $atts['status']) {
// ...
} elseif ('favourites' == $atts['status']) {
$countQuery = $countQuery->where('is_favourite', '=', 1);
} else {
$countQuery = $countQuery->where('status', '=', sanitize_key($atts['status']));
}
if ($atts['payment_status'] && defined('FLUENTFORMPRO') && 'all' != $atts['payment_status']) {
$countQuery = $countQuery->where('payment_status', '=', sanitize_key($atts['payment_status']));
}
$total = $countQuery->count();
if ($atts['substract_from']) {
$total = intval($atts['substract_from']) - $total;
}
if ('yes' == $atts['hide_on_zero'] && !$total || $total < 0) {
return '';
}
return $total;
} elseif ('created_at' == $atts['info']) {
if ($atts['date_format']) {
$dateFormat = $atts['date_format'];
} else {
$dateFormat = get_option('date_format') . ' ' . get_option('time_format');
}
return date($dateFormat, strtotime($form->created_at));
} elseif ('updated_at' == $atts['info']) {
if ($atts['date_format']) {
$dateFormat = $atts['date_format'];
} else {
$dateFormat = get_option('date_format') . ' ' . get_option('time_format');
}
return date($dateFormat, strtotime($form->updated_at));
} elseif ('payment_total' == $atts['info']) {
if (!defined('FLUENTFORMPRO')) {
return '';
}
global $wpdb;
$countQuery = wpFluent()
->table('fluentform_submissions')
->select(wpFluent()->raw('SUM(payment_total) as payment_total'))
->where('form_id', $formId);
if ('trashed' != $atts['status'] && 'no' == $atts['with_trashed']) {
$countQuery = $countQuery->where('status', '!=', 'trashed');
}
if ('all' == $atts['status']) {
// ...
} elseif ('favourites' == $atts['status']) {
$countQuery = $countQuery->where('is_favourite', '=', 1);
} else {
$countQuery = $countQuery->where('status', '=', sanitize_key($atts['status']));
}
if ('all' == $atts['payment_status']) {
// ...
} elseif ($atts['payment_status']) {
$countQuery = $countQuery->where('payment_status', '=', sanitize_key($atts['payment_status']));
}
$row = $countQuery->first();
$total = 0;
if ($row) {
$total = $row->payment_total;
}
if ($atts['substract_from']) {
$total = intval($atts['substract_from'] * 100) - $total;
}
if ('yes' == $atts['hide_on_zero'] && !$total) {
return '';
}
if ('yes' == $atts['currency_formatted']) {
$currency = \FluentFormPro\Payments\PaymentHelper::getFormCurrency($formId);
return \FluentFormPro\Payments\PaymentHelper::formatMoney($total, $currency);
}
if (!$total) {
return 0;
}
return $total / 100;
}
return '';
});
Fluentform [ff_get] Shortcode
The ‘ff_get’ shortcode is a powerful tool in FluentForm. It retrieves data from a specified parameter in the URL. The PHP code for this shortcode checks if the parameter exists and if it has a value. If the value is an array, it converts it into a string.
Shortcode: [ff_get]
Parameters
Here is a list of all possible ff_get shortcode parameters and attributes:
param
– Defines the specific parameter to be fetched from the server request
Examples and Usage
Basic example – Displaying the value of a single parameter using the ff_get shortcode.
[ff_get param="username"]
Here, the shortcode [ff_get param=”username”] will return the value of the ‘username’ parameter that is passed in the URL. If the URL is www.example.com/?username=johndoe, the shortcode will display ‘johndoe’.
Advanced examples
Using the ff_get shortcode to display multiple parameters separated by a comma.
[ff_get param="username, email"]
In this advanced example, the shortcode [ff_get param=”username, email”] is used to get the value of both ‘username’ and ’email’ parameters from the URL. If the URL is www.example.com/?username=johndoe&email=johndoe@example.com, the shortcode will display ‘johndoe, johndoe@example.com’.
PHP Function Code
In case you have difficulties debugging what causing issues with [ff_get]
shortcode, check below the related PHP functions code.
Shortcode PHP function:
$this->app->addShortCode('ff_get', function ($atts) {
$atts = shortcode_atts([
'param' => '',
], $atts);
$value = $this->app->request->get($atts['param']);
if ($atts['param'] && $value) {
if (is_array($value)) {
return implode(', ', $value);
}
return esc_html($value);
}
return '';
});
Conclusion
Now that you’ve learned how to embed the Fluentform Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply