Contact Form Shortcode

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

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

Plugin Icon
Contact Form Plugin

"Contact Form Plugin is a user-friendly tool for WordPress. It allows you to effortlessly design and integrate customized contact forms on your website, enhancing user engagement and interaction."

★★☆✩✩ (17) Active Installs: 4000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [easy-contactform]

Contact Form [easy-contactform] Shortcode

The Easy Contact Form shortcode allows you to embed a contact form within your WordPress site. This shortcode fetches a specific contact form using its ‘id’. It then enqueues necessary scripts and styles, and generates the contact form on the frontend. If the form doesn’t exist, it displays a loading gif.

Shortcode: [easy-contactform]

Parameters

Here is a list of all possible easy-contactform shortcode parameters and attributes:

  • id – An optional parameter used to specify the unique ID(s) of the contact form(s). If multiple IDs are given, they should be separated by commas. This allows for the display of specific forms on the webpage.

Examples and Usage

Basic example – A simple usage of the shortcode to display a contact form using the form’s ID.

[easy-contactform id=1 /]

Advanced examples

Displaying multiple contact forms on the same page by passing multiple IDs separated by commas.

[easy-contactform id=1,2,3 /]

Using the shortcode without passing any ID. In this case, the shortcode will display the contact forms based on the order they were created.

[easy-contactform /]

Note: The shortcode [easy-contactform /] without any ID will only work if there is at least one contact form created in the system. If there are no contact forms created, it will display a loading image.

PHP Function Code

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

Shortcode line:

add_shortcode( 'easy-contactform', 'ecf_shortcode' );

Shortcode PHP function:

function ecf_shortcode( $attsn ) {

	extract( shortcode_atts( array(
	'id' => -1
	), $attsn ) );
	
	ob_start();

if ( $id != '' ) {
	
	$finid = explode(",", $id);
	$medinarr = $finid;

	$ecfargs = array(
		'post__in' => $finid, 
		'post_type' => 'easycontactform',
		);
	}   


 
$ecf_query = new WP_Query( $ecfargs );

if ( $ecf_query->have_posts() ):


while ( $ecf_query->have_posts() ) : $ecf_query->the_post();


	if( has_filter( 'ecf_addons_frontend_enqueue' ) ) {
		
		apply_filters( 'ecf_addons_frontend_enqueue', get_the_id() );
		
		}

	wp_enqueue_script( 'ecf-validate' );
	wp_enqueue_style( 'ecf-frontend-css' );
	wp_enqueue_script( 'ecf-ladda-spin' );
	wp_enqueue_script( 'ecf-notify' );
	wp_enqueue_script( 'ecf-ladda-js' );
	wp_enqueue_script( 'ecf-ladda' );
		
	global $is_IE;
	if ( $is_IE ) {
		wp_enqueue_script( 'ecf-placeholder' );
		}
		
		// START GENERATE FORM
		require_once 'ecf-template.php';
		ecf_markup_generator( get_the_id(), ecfRandomString(6) );

?>

<?php
endwhile;
else:
echo '<div style="clear: both; display: block; text-align:center; margin-left: auto; margin-right: auto;"><img src="'.plugins_url('images/ajax-loader.gif' , __FILE__).'" width="32" height="32"/></div>'; 

$contnt = ob_get_clean();
return $contnt;  

endif;
wp_reset_postdata();


$content = ob_get_clean();
return $content;
	
}

Code file location:

contact-form-lite/contact-form-lite/inc/ecf-shortcode.php

Conclusion

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

Comments

Leave a Reply

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