Below, you’ll find a detailed guide on how to add the Mollie Forms 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 Mollie Forms Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the Mollie Forms Plugin and the shortcodes it provides:
"Mollie Forms is a dynamic WordPress plugin that simplifies the process of creating interactive and responsive forms. It integrates seamlessly with Mollie payment system for easy transactions."
- [rfmp]
- [rfmp-total]
- [rfmp-goal]
Mollie Forms [rfmp] Shortcode
The Mollie Forms shortcode, ‘rfmp’, allows you to embed a specific form within your WordPress site. By passing the form ID to the shortcode, it retrieves the corresponding form. If no ID is provided or the form doesn’t exist, it will return an error message. The shortcode also processes form submissions and handles redirects after payments. Additionally, it can customize form fields based on the stored metadata, such as field type, label, value, class, and whether it’s required. The shortcode renders the form on your website, providing a seamless user experience.
Shortcode: [rfmp]
Parameters
Here is a list of all possible rfmp shortcode parameters and attributes:
id
– Unique identifier of the Mollie form_rfmp_locale
– Sets the locale for the form, default is ‘nl_NL’_rfmp_class_form
– The CSS class of the form_rfmp_fields_type
– The type of fields in the form_rfmp_fields_label
– The label for each field in the form_rfmp_fields_value
– The value for each field in the form_rfmp_fields_class
– The CSS class for each field in the form_rfmp_fields_required
– Whether each field is required or not_rfmp_label_display
– How the label is displayed for each field
Examples and Usage
Basic example – Display a Mollie form by referencing the form ID
[rfmp id=123 /]
Advanced examples
Display a Mollie form and process a POST submission. The form will be displayed if the request method is POST and the form ID matches the submitted form ID.
[rfmp id=123 mollie-forms-post=123 /]
Display a Mollie form and process a GET payment. The form will be displayed if a GET payment parameter is set and the form ID matches the payment ID.
[rfmp id=123 payment=abc123 /]
Display a Mollie form with a form field. The form field is set by specifying the field type, label, value, class, and whether it’s required or not.
[rfmp id=123 form_field="type=text&label=Name&value=John&class=input&required=true" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [rfmp]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('rfmp', [$this, 'addMollieFormsShortcode']);
Shortcode PHP function:
function addMollieFormsShortcode($atts)
{
$atts = shortcode_atts(['id' => ''], $atts);
if (!isset($atts['id']) || empty($atts['id'])) {
return __('Please pass the form ID to the shortcode', 'mollie-forms');
}
$post = get_post($atts['id']);
if (!isset($post->ID) || !$post->ID) {
return __('Form not found', 'mollie-forms');
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['mollie-forms-post']) &&
$_POST['mollie-forms-post'] == $post->ID) {
return $this->processSubmit($post->ID);
}
if (isset($_GET['payment'])) {
return $this->processRedirect($post->ID, $_GET['payment']);
}
$locale = get_post_meta($post->ID, '_rfmp_locale', true) ?: 'nl_NL';
$formClass = get_post_meta($post->ID, '_rfmp_class_form', true);
$builder = new FormBuilder($post->ID, $formClass);
$fields = get_post_meta($post->ID, '_rfmp_fields_type', true);
foreach ($fields as $key => $type) {
$label = get_post_meta($post->ID, '_rfmp_fields_label', true);
$options = get_post_meta($post->ID, '_rfmp_fields_value', true);
$class = get_post_meta($post->ID, '_rfmp_fields_class', true);
$required = get_post_meta($post->ID, '_rfmp_fields_required', true);
$labelDisplay = get_post_meta($post->ID, '_rfmp_label_display', true);
$name = 'form_' . $post->ID . '_field_' . $key;
$atts = [
'name' => $name,
'id' => $name,
'value' => isset($_POST[$name]) ? $_POST[$name] : (isset($_GET[$name]) ? $_GET[$name] : ''),
'label' => $label[$key],
'class' => $class[$key],
];
if ($required[$key]) {
$atts['required'] = '';
}
$defaultCountry = explode('_', $locale);
if ($type == 'country' && $atts['value'] == '' && isset($defaultCountry[1])) {
$atts['value'] = $defaultCountry[1];
}
if ($options[$key]) {
$atts['options'] = explode('|', $options[$key]);
}
if ($labelDisplay == 'placeholder' || $labelDisplay == 'both') {
$atts['placeholder'] = $label[$key] . ($required[$key] ? ' *' : '');
}
if ($labelDisplay != 'placeholder') {
$required = !($type == 'discount_code') && isset($atts['required']);
$builder->addLabel($atts['name'], $atts['label'], $required);
}
$builder->addField($type, $atts);
}
return $builder->render();
}
Code file location:
mollie-forms/mollie-forms/classes/Form.php
Mollie Forms [rfmp-total] Shortcode
The Mollie-Forms plugin shortcode ‘rfmp-total’ retrieves and displays the total payments received for a form. The shortcode allows customization of the ‘start’ value and the ‘id’ of the form. It uses a SQL query to sum up all paid payments from the form. The result is then formatted to the correct currency and displayed on the website.
Shortcode: [rfmp-total]
Parameters
Here is a list of all possible rfmp-total shortcode parameters and attributes:
id
– Unique identifier of the mollie formstart
– Initial amount to start adding payments from
Examples and Usage
Basic example – The shortcode displays the total amount of payments made through a specific form. The ‘id’ attribute represents the form ID.
[rfmp-total id=1 /]
Advanced examples
Displays the total amount of payments made through multiple forms. The ‘id’ attribute accepts multiple form IDs separated by commas.
[rfmp-total id="1,2,3" /]
Displays the total amount of payments made through a specific form, starting from a specified amount. The ‘start’ attribute represents the starting amount.
[rfmp-total id=1 start=100.00 /]
Displays the total amount of payments made through multiple forms, starting from a specified amount. The ‘id’ and ‘start’ attributes represent the form IDs and the starting amount, respectively.
[rfmp-total id="1,2,3" start=100.00 /]
PHP Function Code
In case you have difficulties debugging what causing issues with [rfmp-total]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('rfmp-total', [$this, 'addMollieFormsTotalShortcode']);
Shortcode PHP function:
function addMollieFormsTotalShortcode($atts)
{
$atts = shortcode_atts([
'id' => '',
'start' => 0.00,
], $atts);
$total = (float) $atts['start'];
foreach (explode(',', str_replace(' ', '', $atts['id'])) as $formId) {
$post = get_post($formId);
if (!$post->ID) {
return 'Form with ID ' . $formId . ' not found';
}
$total += $this->db->get_var("SELECT SUM(payments.amount) FROM {$this->mollieForms->getPaymentsTable()} payments INNER JOIN {$this->mollieForms->getRegistrationsTable()} registrations ON payments.registration_id = registrations.id AND registrations.post_id='" .
esc_sql($post->ID) .
"' WHERE payments.payment_status='paid' AND payments.payment_mode='live'");
}
$currency = get_post_meta($post->ID, '_rfmp_currency', true) ?: 'EUR';
$decimals = $this->helpers->getCurrencies($currency);
$symbol = $this->helpers->getCurrencySymbol($currency);
return $symbol . ' ' . number_format($total, $decimals, ',', '.');
}
Code file location:
mollie-forms/mollie-forms/classes/Form.php
Mollie Forms [rfmp-goal] Shortcode
The Mollie Forms shortcode is a feature that allows you to add a donation goal to your WordPress site. This shortcode uses the ‘addMollieFormsGoalShortcode’ function to fetch the total sum of paid payments and compares it with the set goal. If the goal is reached or exceeded, it displays a custom message. If not, it shows the remaining amount in the specified currency.
Shortcode: [rfmp-goal]
Parameters
Here is a list of all possible rfmp-goal shortcode parameters and attributes:
id
– The unique identifier of the contact form.goal
– The target amount to be collected from the payments.text
– The message displayed when the goal is reached.
Examples and Usage
Basic example – Show the goal amount of a specific form.
[rfmp-goal id=5 goal=1000]
Advanced examples
Display the goal amount of a specific form and customize the text shown when the goal is reached.
[rfmp-goal id=5 goal=1000 text="Congratulations! Goal achieved!"]
Use the shortcode without specifying a goal. In this case, the goal will be retrieved from the form settings.
[rfmp-goal id=5]
Display the goal amount of a specific form in a different currency. The currency will be converted according to the exchange rates set in the form settings.
[rfmp-goal id=5 goal=1000 currency="USD"]
PHP Function Code
In case you have difficulties debugging what causing issues with [rfmp-goal]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('rfmp-goal', [$this, 'addMollieFormsGoalShortcode']);
Shortcode PHP function:
function addMollieFormsGoalShortcode($atts)
{
$atts = shortcode_atts([
'id' => '',
'goal' => '',
'text' => __('Goal reached!', 'mollie-forms'),
], $atts);
$post = get_post($atts['id']);
$goal = $atts['goal'];
if (!$post->ID) {
return __('Form not found', 'mollie-forms');
}
if ($goal < 0) {
return __('Goal must be higher then 0', 'mollie-forms');
}
$total = $this->db->get_var("SELECT SUM(payments.amount) FROM {$this->mollieForms->getPaymentsTable()} payments INNER JOIN {$this->mollieForms->getRegistrationsTable()} registrations ON payments.registration_id = registrations.id AND registrations.post_id='" .
esc_sql($post->ID) .
"' WHERE payments.payment_status='paid' AND payments.payment_mode='live'");
$goal = (int) $goal - $total;
if ($goal <= 0) {
return __($atts['text'], 'mollie-forms');
}
$currency = get_post_meta($post->ID, '_rfmp_currency', true) ?: 'EUR';
$decimals = $this->helpers->getCurrencies($currency);
$symbol = $this->helpers->getCurrencySymbol($currency);
return $symbol . ' ' . number_format($goal, $decimals, ',', '.');
}
Code file location:
mollie-forms/mollie-forms/classes/Form.php
Conclusion
Now that you’ve learned how to embed the Mollie Forms 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