Formstack Online Forms Shortcode

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

Before starting, here is an overview of the Formstack Online Forms Plugin and the shortcodes it provides:

Plugin Icon
Formstack Online Forms

"Formstack Online Forms is a powerful WordPress plugin that allows you to effortlessly create and manage custom online forms, surveys, and questionnaires directly on your website."

★★✩✩✩ (8) Active Installs: 2000+ Tested with: 5.1.17 PHP Version: false
Included Shortcodes:
  • [render_formstack_shortcode]

Formstack Online Forms [render_formstack_shortcode] Shortcode

The Formstack shortcode is a PHP function that renders a Formstack form on your WordPress site. It checks form ID and view key, retrieves an ad, and displays the form.

Shortcode: [render_formstack_shortcode]

Parameters

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

  • id – Unique identifier for the specific form.
  • viewkey – Key used to view the specific form.
  • nojquery – If set to true, jQuery will not be loaded.
  • nojqueryui – If set to true, jQuery UI will not be loaded.
  • nomodernizr – If set to true, Modernizr will not be loaded.
  • no_style – If set to true, default form styles will not be applied.
  • no_style_strict – If set to true, strict form styles will not be applied.

Examples and Usage

Basic Example – Displaying a Formstack form using ID and viewkey

[formstack_shortcode id="123456" viewkey="abc123" /]

This shortcode will render the Formstack form with the ID of “123456” and the viewkey of “abc123”. The ID and viewkey can be found in the Formstack form settings.

Advanced Examples

Displaying a Formstack form using ID and viewkey, without jQuery, jQueryUI, and Modernizr

[formstack_shortcode id="123456" viewkey="abc123" nojquery="true" nojqueryui="true" nomodernizr="true" /]

This shortcode will render the Formstack form with the ID of “123456” and the viewkey of “abc123”, and it will not load jQuery, jQueryUI, or Modernizr. This is useful if your WordPress theme or another plugin is already loading these libraries, to avoid conflicts or loading the same library multiple times.

Displaying a Formstack form using ID and viewkey, without the default Formstack styles

[formstack_shortcode id="123456" viewkey="abc123" no_style="true" /]

This shortcode will render the Formstack form with the ID of “123456” and the viewkey of “abc123”, and it will not apply the default Formstack styles. This is useful if you want to apply your own custom CSS styles to the form.

PHP Function Code

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

Shortcode line:

add_shortcode( $shortcode, array( $this, 'render_formstack_shortcode' ) );

Shortcode PHP function:

function render_formstack_shortcode( $atts, $content = null, $code = '' ) {

		if ( empty( $atts['id'] ) || empty( $atts['viewkey'] ) || is_feed() ) {
			return '';
		}
		$atts = wp_parse_args( $atts, array(
			'id'          => '',
			'viewkey'     => '',
			'nojquery'    => 'false',
			'nojqueryui'  => 'false',
			'nomodernizr' => 'false',
			'no_style'       => 'false',
			'no_style_strict' => 'false',
		) );
		// An ad request. Displays after the actual form.
		$wp = wp_remote_get( "https://www.formstack.com/forms/wp-ad.php?form={$atts['id']}" );

		$extras = formstack_get_extra_url_params( $atts );

		$script_url = add_query_arg( $extras, "https://www.formstack.com/forms/js.php?{$atts['id']}-{$atts['viewkey']}" );
		$noscript_url = add_query_arg( $extras, "https://www.formstack.com/forms/?{$atts['id']}-{$atts['viewkey']}" );

		ob_start();
		?>
		<script type="text/javascript" src="<?php echo esc_url( $script_url ); ?>"></script>
		<noscript>
			<a href="<?php echo esc_url( $noscript_url ); ?>" title="<?php esc_attr_e( 'Online Form', 'formstack' ); ?>">
				<?php esc_html_e( 'Online Form', 'formstack' ); ?>
			</a>
		</noscript>
		<?php
		echo wp_kses_post( wp_remote_retrieve_body( $wp ) );

		return ob_get_clean();
	}

Code file location:

formstack/formstack/plugin.php

Conclusion

Now that you’ve learned how to embed the Formstack Online Forms 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 *