Metform Elementor Contact Form Builder Shortcodes

Below, you’ll find a detailed guide on how to add the Metform Elementor Contact Form Builder 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 Metform Elementor Contact Form Builder Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Metform Elementor Contact Form Builder Plugin and the shortcodes it provides:

Plugin Icon
Metform Elementor Contact Form Builder

"Metform Elementor Contact Form Builder is a dynamic plugin that enables easy creation and customization of contact forms. Tailor forms to your needs, enhancing user engagement and data collection."

★★★★☆ (345) Active Installs: 200000+ Tested with: 6.3.2 PHP Version: 7.4
Included Shortcodes:
  • [metform]
  • [mf_thankyou]
  • [mf_first_name]
  • [mf_last_name]
  • [mf_payment_status]
  • [mf_transaction_id]
  • [mf]

Metform [metform] Shortcode

The MetForm shortcode is a powerful tool for rendering forms on your WordPress site. It allows you to display a specified form by simply inserting the shortcode into your content. This shortcode uses the ‘render_form’ function to enqueue necessary form assets and define the form’s ID. It then returns the form content wrapped in a ‘mf-form-shortcode’ div, ready for display.

Shortcode: [metform]

Parameters

Here is a list of all possible metform shortcode parameters and attributes:

  • form_id – Unique identifier for the specific form to be displayed

Examples and Usage

Basic example – The shortcode displays a form by referencing the form ID. The form ID should be replaced with the actual form ID you want to display.

[metform form_id="1" /]

Advanced examples

Using the shortcode to display a form by referencing a different form ID. The form will load based on the form ID provided.

[metform form_id="2" /]

Using the shortcode to display a form by referencing multiple form IDs. The forms will load in the order of the form IDs provided.

[metform form_id="1,2,3" /]

Please note, in these examples, ‘1’, ‘2’, and ‘1,2,3’ are the form IDs. You should replace them with the actual form IDs you want to display.

PHP Function Code

In case you have difficulties debugging what causing issues with [metform] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('metform', [$this, 'render_form']);

Shortcode PHP function:

function render_form($atts)
	{
		$this->enqueue_form_assets();

		$attributes = shortcode_atts(array(
			'form_id' => 'test',
		), $atts);

		return '<div class="mf-form-shortcode">' . \MetForm\Utils\Util::render_form_content($attributes['form_id'], $attributes['form_id']) . '</div>';
	}

Code file location:

metform/metform/base/shortcode.php

Metform [mf_thankyou] Shortcode

The Metform shortcode ‘mf_thankyou’ generates a custom thank you message post-payment. It verifies payment status and transaction ID, then displays a personalized message.

Shortcode: [mf_thankyou]

Parameters

Here is a list of all possible mf_thankyou shortcode parameters and attributes:

  • fname – First name of the person filling out the form
  • lname – Last name of the person filling out the form
  • id – Unique identifier of the form submission

Examples and Usage

Basic example – This shortcode will display a thank you message for a user who has made a payment. The shortcode doesn’t require any parameters to function.

[mf_thankyou /]

Advanced examples

Using the shortcode to display a personalized thank you message. The shortcode requires the ‘fname’ parameter to function, which is the user’s first name.

[mf_thankyou fname="John" /]

Using the shortcode to display a personalized thank you message with both first name and last name. The shortcode requires both ‘fname’ and ‘lname’ parameters to function.

[mf_thankyou fname="John" lname="Doe" /]

It’s important to note that the ‘fname’ and ‘lname’ parameters should match the names of the fields in the form that the user has submitted. If the names do not match, the shortcode won’t be able to retrieve the user’s name, and the thank you message will not be personalized.

PHP Function Code

In case you have difficulties debugging what causing issues with [mf_thankyou] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('mf_thankyou', [$this, 'render_thank_you_page']);

Shortcode PHP function:

function render_thank_you_page($atts)
	{
		if($GLOBALS['pagenow'] == 'post.php'){
			return;
		}
		global $post;
		
		$this->enqueue_form_assets();

		$a = shortcode_atts(array(
			'fname' => '',
			'lname' => '',
		), $atts);

		//phpcs:ignore WordPress.Security.NonceVerification -- Nonce can't be added, Its a callback function of 'add_shortcode'
		$post_id = isset($_GET['id']) ? sanitize_text_field(wp_unslash($_GET['id'])) : '';
		// ##check transient id and session hashed token 
		if(empty($post_id)){
			return ;
		}
		$token_str = $post_id.get_current_user_id();
		$access_status_check = $this->transient_and_session_checker($token_str, $post_id);
		if(!$access_status_check){
			return; // return nothing or below invalid access 
			// return "invalid access";
		}
		
		$postMeta = get_post_meta(
			$post_id,
			'metform_entries__form_data',
			true
		);
		$first_name = !empty($postMeta[$a['fname']]) ? $postMeta[$a['fname']] : '';

		$payment_status = get_post_meta(
			$post_id,
			'metform_entries__payment_status',
			true
		);

		$tnx_id = get_post_meta(
			$post_id,
			'metform_entries__payment_trans',
			true
		);
	
		$msg = '';

		if ($payment_status == 'paid') {
			$msg = $first_name . esc_html__(' Thank you for your payment.', 'metform'). '<br>' . esc_html__(' Your transcation ID : ', 'metform' ). $tnx_id;
		} else {
			$msg = esc_html__('Thank you . Your payment status : ', 'metform') . $payment_status;
		}
		
		return $msg;
	}

Code file location:

metform/metform/base/shortcode.php

Metform [mf_first_name] Shortcode

The MetForm plugin shortcode ‘mf_first_name’ retrieves and displays the first name from a specific form entry. It first checks for valid access, then pulls the ‘first_name’ field from the form data. This shortcode is useful for personalizing content based on user input. It ensures data security by verifying access before displaying information.

Shortcode: [mf_first_name]

Examples and Usage

Basic example – The shortcode ‘mf_first_name’ is used to render the first name of a user. It fetches the first name from the post meta data of a given post ID.

[mf_first_name id=1 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [mf_first_name] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('mf_first_name', [$this, 'render_first_name']);

Shortcode PHP function:

function render_first_name($atts)
	{
		$this->enqueue_form_assets();
		//phpcs:ignore WordPress.Security.NonceVerification -- Nonce can't be added, Its a callback function of 'add_shortcode'
		$post_id = isset($_GET['id']) ? sanitize_text_field(wp_unslash($_GET['id'])) : '';
		// ##check transient id and session hashed token 
		if(empty($post_id)){
			return ;
		}
		$token_str = $post_id.get_current_user_id();
		$access_status_check = $this->transient_and_session_checker($token_str, $post_id);
		if(!$access_status_check){
			return; // return nothing or below invalid access 
			// return "invalid access";
		}

		$first_name = get_post_meta(
			$post_id,
			'metform_entries__form_data',
			true
		)['mf-listing-fname'];
		return esc_html($first_name);
	}

Code file location:

metform/metform/base/shortcode.php

Metform [mf_last_name] Shortcode

The Metform shortcode ‘mf_last_name’ retrieves the last name from the form data of a specific post. It first checks for a valid post ID and user access, ensuring security. The PHP function ‘render_last_name’ is called upon, which enqueues form assets, validates the post ID and user access, then fetches the last name from the post metadata.

Shortcode: [mf_last_name]

Examples and Usage

Basic example – The following shortcode will render the last name stored in the post meta of the specified post ID.

[mf_last_name id=1 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [mf_last_name] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('mf_last_name', [$this, 'render_last_name']);

Shortcode PHP function:

function render_last_name($atts)
	{
		$this->enqueue_form_assets();
		//phpcs:ignore WordPress.Security.NonceVerification -- Nonce can't be added, Its a callback function of 'add_shortcode'
		$post_id = isset($_GET['id']) ? sanitize_text_field(wp_unslash($_GET['id'])) : '';
		// ##check transient id and session hashed token 
		if(empty($post_id)){
			return ;
		}
		$token_str = $post_id.get_current_user_id();
		$access_status_check = $this->transient_and_session_checker($token_str, $post_id);
		if(!$access_status_check){
			return; // return nothing or below invalid access 
			// return "invalid access";
		}

		$last_name = get_post_meta(
			$post_id,
			'metform_entries__form_data',
			true
		)['mf-listing-lname'];
		return esc_html($last_name);
	}

Code file location:

metform/metform/base/shortcode.php

Metform [mf_payment_status] Shortcode

The Metform Plugin shortcode ‘mf_payment_status’ retrieves and displays the payment status of a form entry. It first verifies access by checking the transient ID and session token. If access is granted, it fetches the payment status from the post metadata. If access is denied, it returns nothing, ensuring secure data handling.

Shortcode: [mf_payment_status]

Parameters

Here is a list of all possible mf_payment_status shortcode parameters and attributes:

  • id – A specific marker for the contact form

Examples and Usage

Basic example – Utilizing the shortcode to display the payment status of a post by referencing its ID.

[mf_payment_status id=1 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [mf_payment_status] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('mf_payment_status', [$this, 'render_payment_status']);

Shortcode PHP function:

function render_payment_status($atts)
	{
		$this->enqueue_form_assets();
		//phpcs:ignore WordPress.Security.NonceVerification -- Nonce can't be added, Its a callback function of 'add_shortcode'
		$post_id = isset($_GET['id']) ? sanitize_text_field(wp_unslash($_GET['id'])) : '';
		// ##check transient id and session hashed token 
		if(empty($post_id)){
			return ;
		}
		$token_str = $post_id.get_current_user_id();
		$access_status_check = $this->transient_and_session_checker($token_str, $post_id);
		if(!$access_status_check){
			return; // return nothing or below invalid access 
			// return "invalid access";
		}

		$payment_status = get_post_meta(
			$post_id,
			'metform_entries__payment_status',
			true
		);
		return $payment_status;
	}

Code file location:

metform/metform/base/shortcode.php

Metform [mf_transaction_id] Shortcode

The Metform Plugin shortcode ‘mf_transaction_id’ retrieves a transaction ID associated with a specific post. It utilizes the ‘get_post_meta’ function to fetch the ‘metform_entries__payment_trans’ metadata, which stores the transaction ID.

Shortcode: [mf_transaction_id]

Examples and Usage

Basic example – Renders the transaction id associated with a specific post. The post id is passed as a parameter in the URL.

[mf_transaction_id]

Advanced examples

Using the shortcode to fetch the transaction id for a specific post id. The post id is passed as a parameter in the URL. If the post id is not found or the current user does not have access, it will return an empty string.

[mf_transaction_id id=123]

PHP Function Code

In case you have difficulties debugging what causing issues with [mf_transaction_id] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('mf_transaction_id', [$this, 'render_transaction_id']);

Shortcode PHP function:

function render_transaction_id($atts)
	{
		$this->enqueue_form_assets();
		//phpcs:ignore WordPress.Security.NonceVerification -- Nonce can't be added, Its a callback function of 'add_shortcode'
		$post_id = isset($_GET['id']) ? sanitize_text_field(wp_unslash($_GET['id'])) : '';
		// ##check transient id and session hashed token 
		if(empty($post_id)){
			return ;
		}
		$token_str = $post_id.get_current_user_id();
		$access_status_check = $this->transient_and_session_checker($token_str, $post_id);
		if(!$access_status_check){
			return; // return nothing or below invalid access 
			// return "invalid access";
		}

		$tnx_id = get_post_meta(
			$post_id,
			'metform_entries__payment_trans',
			true
		);

		return $tnx_id;
	}

Code file location:

metform/metform/base/shortcode.php

Metform [mf] Shortcode

The Metform shortcode ‘mf’ is designed to render specific form fields. It fetches post metadata associated with form entries, ensuring secure and valid access. The shortcode first verifies the post ID and user access. If invalid, it returns nothing or an ‘invalid access’ message. Then, it retrieves the form data from the post metadata. If no entry is found, it displays a ‘No entry found’ message. If the specified field exists in the form data, its content is returned. If the field content is an array, it’s converted into a string.

Shortcode: [mf]

Parameters

Here is a list of all possible mf shortcode parameters and attributes:

  • field – name of the field to be retrieved from the form’s data
  • id – unique identifier of the post containing the form

Examples and Usage

Basic example – Utilizing the shortcode to display a specific field from the ‘metform_entries__form_data’ post meta of a post. The ID of the post is passed through the URL.

[mf field="fieldname" /]

For example, if you want to display the ’email’ field from the form data, you can use the following shortcode:

[mf field="email" /]

Advanced examples – As the shortcode function ‘render_mf_field’ does not support multiple parameters, you can only pass one field name at a time. However, you can use the shortcode multiple times to display different fields.

For instance, if you want to display both ’email’ and ‘name’ fields, you can use the following shortcodes:

[mf field="email" /]
[mf field="name" /]

Please note that the shortcode will only work if the post ID is passed through the URL and the current user has the right access token. If the specified field does not exist in the post meta, it will display ‘No entry found’.

PHP Function Code

In case you have difficulties debugging what causing issues with [mf] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('mf',[$this,'render_mf_field']);

Shortcode PHP function:

function render_mf_field($atts){
		$this->enqueue_form_assets();

		$a = shortcode_atts(array(
			'field' => ''
		),$atts);

		//phpcs:ignore WordPress.Security.NonceVerification -- Nonce can't be added, Its a callback function of 'add_shortcode'
		$post_id = isset($_GET['id']) ? sanitize_text_field(wp_unslash($_GET['id'])) : '';
		// ##check transient id and session hashed token 
		if(empty($post_id)){
			return ;
		}
		$token_str = $post_id.get_current_user_id();
		$access_status_check = $this->transient_and_session_checker($token_str, $post_id);
	
		if(!$access_status_check){
			return; // return nothing or below invalid access 
			// return "invalid access";
		}

		$field = get_post_meta(
			$post_id,
			'metform_entries__form_data',
			true
		);
		
		if(!is_array($field)){
			return esc_html__("No entry found.", 'metform')."<br>"; // br added if one page have multiple shortcode which is not available
		}
		 
		if(!key_exists($a['field'], $field)){
			return  $a['field'] . esc_html__("No entry found.", 'metform').'<br>';
		}
		
		$field = get_post_meta($post_id, 'metform_entries__form_data',true) [$a['field']];

		return is_array($field) ? map_deep(implode(" , ",$field), 'esc_html') : esc_html($field);
	}

Code file location:

metform/metform/base/shortcode.php

Conclusion

Now that you’ve learned how to embed the Metform Elementor Contact Form Builder 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.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *