Below, you’ll find a detailed guide on how to add the Forminator Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Forminator Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Forminator Plugin and the shortcodes it provides:
"Forminator – Contact Form, Payment Form & Custom Form Builder is a versatile WordPress plugin. It simplifies the creation and management of contact forms, payment forms, and custom forms."
- [forminator_form]
Forminator [forminator_form] Shortcode
The Forminator shortcode is used to render forms dynamically in WordPress. It checks for the form’s ID and if it’s being previewed, then displays the form accordingly.
Shortcode: [forminator_form]
Parameters
Here is a list of all possible forminator_form shortcode parameters and attributes:
id
– unique identifier of the contact form.is_preview
– determines if the form is in preview mode.preview_data
– contains data for the form preview.
Examples and Usage
Basic example – A simple usage of the forminator shortcode that displays a form with a specified ID.
[forminator_form id=1 /]
Advanced examples
Utilizing the shortcode to display a form with a specified ID and enabling the preview mode. The preview mode allows you to view the form as it would appear on the frontend without actually submitting any data.
[forminator_form id=1 is_preview=true /]
Adding custom preview data to the form. This can be useful for testing your form with specific data without having to manually input it each time.
[forminator_form id=1 is_preview=true preview_data="name=John&email=john@example.com" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [forminator_form]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'forminator_' . static::$module_slug, array( $this, 'render_shortcode' ) );
Shortcode PHP function:
function render_shortcode( $atts = array() ) {
// use already created instance if already available.
$view = new static();
if ( ! isset( $atts['id'] ) ) {
return $view->message_required();
}
$is_preview = isset( $atts['is_preview'] ) ? $atts['is_preview'] : false;
$is_preview = filter_var( $is_preview, FILTER_VALIDATE_BOOLEAN );
if ( $is_preview === false && forminator_is_page_builder_preview() ) {
$is_preview = true;
}
$is_preview = apply_filters( 'forminator_render_shortcode_is_preview', $is_preview );
$preview_data = isset( $atts['preview_data'] ) ? $atts['preview_data'] : array();
ob_start();
$view->display( $atts['id'], $is_preview, $preview_data );
$lead_data = ! empty( static::$lead_data ) ? static::$lead_data : array();
$view->ajax_loader( $is_preview, $preview_data, $lead_data );
return ob_get_clean();
}
Code file location:
forminator/forminator/library/render/class-render-form.php
Conclusion
Now that you’ve learned how to embed the Forminator Plugin shortcode, 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