Brilliant Web-to-Lead for Salesforce Shortcode

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

Before starting, here is an overview of the Brilliant Web-to-Lead for Salesforce Plugin and the shortcodes it provides:

Plugin Icon
Brilliant Web-to-Lead for Salesforce

"Brilliant Web-to-Lead for Salesforce is a powerful plugin that seamlessly connects your WordPress site to Salesforce. It effectively captures leads and syncs data between platforms."

★★★★✩ (38) Active Installs: 4000+ Tested with: 5.9.8 PHP Version: 7.4
Included Shortcodes:
  • [salesforce]

Brilliant Web-to-Lead for Salesforce [salesforce] Shortcode

The Salesforce-Wordpress-to-Lead plugin shortcode is a tool that allows you to create and manage forms in your WordPress site that feed directly into your Salesforce CRM. This shortcode handles form submission, validation, error handling, and successful submission redirect. It ensures that all required fields are filled and validates email addresses. It also includes support for Google ReCaptcha for form security. In essence, it’s a bridge between your WordPress site and Salesforce, streamlining lead collection and management.

Shortcode: [salesforce]

Parameters

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

  • form – Specifies the form number used in the shortcode
  • sidebar – Determines if the form is displayed in the sidebar or not

Examples and Usage

Basic example – Display a Salesforce form with the default settings

[salesforce form=1]

Advanced examples

Display a Salesforce form with a specific ID and disable the sidebar

[salesforce form=2 sidebar=false]

Display a Salesforce form with a specific ID and enable the sidebar

[salesforce form=3 sidebar=true]

Please note that in the shortcode examples above, ‘form’ refers to the ID of the Salesforce form you want to display, and ‘sidebar’ is a boolean that determines whether or not to display the sidebar. If ‘sidebar’ is set to ‘true’, the sidebar will be displayed. If ‘sidebar’ is set to ‘false’, the sidebar will not be displayed.

PHP Function Code

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

Shortcode line:

add_shortcode('salesforce', 'salesforce_form_shortcode');

Shortcode PHP function:

function salesforce_form_shortcode($atts) {

	extract( shortcode_atts( array(
		'form' => '1',
		'sidebar' => false,
	), $atts ) );

	$emailerror = '';
	$captchaerror = '';
	$content = '';

	$form = (int) $form;
	$sidebar = (bool) $sidebar;

	$options = get_option("salesforce2");
	if (!is_array($options))
		$options = salesforce_default_settings();

	//don't submit unless we're in the right shortcode
	if( isset( $_POST['form_id'] ) ){
		$form_id = intval( $_POST['form_id'] );

		if( $form_id != $form ){
			$content = salesforce_form($options, $sidebar, null, $form);

			$layout = salesforce_get_option('layout', $form, $options );

			if( $layout ){
				$layout = 'sf_' . $layout;
			}

			return '<div class="salesforce_w2l_lead ' . sanitize_html_class( $layout ) . '">' . $content . '</div>';

		}

	}

	//this is the right form, continue
	if( isset( $_POST['w2lsubmit'] ) ) {
		$error = false;
		$post = array();

		$has_error = false;


		// field validation
		foreach ($options['forms'][$form]['inputs'] as $id => $input) {

			// get prefixed input name
			$input_name = salesforce_get_input_name( $id );

			if( isset( $_POST[$input_name] ) ){

				$val = $_POST[$input_name];

				if( is_array($val) ){
					$val = array_map( 'trim', $val );
				}else{
					$val = trim( $val );
				}
			}else{
				$val = '';
			}

			$error = array(
				'valid' => false,
				'message' => $options['errormsg'],
			);

			if ( $input['show'] && $input['required'] && strlen( salesforce_maybe_implode( ';', $val ) ) == 0 ) {
				$error['valid'] = false;
			}else{
				$error['valid'] = true;
			}

			if ( ( ($id == 'email' && $input['required'] ) || ( $input['type'] == 'email' && $val ) )  && !is_email($val) ) {
				$error['valid'] = false;

				if( isset( $options['emailerrormsg'] ) && $options['emailerrormsg'] ){
					$error['message'] = $options['emailerrormsg'];
				}else{
					// backwards compatibility
					$error['message'] = __('The email address you entered is not valid.','salesforce');
				}

			}

			$error = apply_filters('sfwp2l_validate_field', $error, $id, $val, $options['forms'][$form]['inputs'][$id] );

			//$error = apply_filters('sfwp2l_'.$id, $error, $id, $options['forms'][$form]['inputs'][$id] );

			$errors[$id] = $error;

			if ( $input['required'] && strlen( salesforce_maybe_implode( ';', $val ) ) == 0 ) {

			//$options['forms'][$form]['inputs'][$id]['error'] = true;

			//	$error = true;
			//} else if ($id == 'email' && $input['required'] && !is_email($_POST[$id]) ) {
			//	$error = true;
			//	$emailerror = true;
			} else {
				if( isset( $_POST[$input_name] ) ){
					if( is_array( $_POST[$input_name] ) ){
						$post[$id] = array_map( 'salesforce_clean_field', $_POST[$input_name] );
					}else{
						$post[$id] = salesforce_clean_field( $_POST[$input_name] );
					}
				}
			}
		}

		if( salesforce_has_captcha( $form_id, $options ) ){

			if( salesforce_get_option('captcha_type', $form_id, $options ) == 'recaptcha' ){

				$recaptcha_valid = false;

				if( isset( $_POST['g-recaptcha-response'] ) && $_POST['g-recaptcha-response'] ){

					$recaptcha_args = array(
						'secret' => salesforce_get_option('recaptcha_secret_key', $form_id, $options ),
						'response' => $_POST['g-recaptcha-response'],
					);

					if( isset( $_SERVER['REMOTE_ADDR'] ) && $_SERVER['REMOTE_ADDR'] != '127.0.0.1' ){
						$recaptcha_args['remoteip'] = $_SERVER['REMOTE_ADDR'];
					}

					$recaptcha_response = wp_safe_remote_post( 'https://www.google.com/recaptcha/api/siteverify', array( 'body' => $recaptcha_args ) );

					$recaptcha_response_body = wp_remote_retrieve_body( $recaptcha_response );

					$recaptcha_response_object = json_decode( $recaptcha_response_body );

					$recaptcha_valid = $recaptcha_response_object->success;

					if( ! $recaptcha_valid ){
						$errors['recaptcha']['valid'] = false;
						$errors['recaptcha']['message'] = __('Failed to verify ReCaptcha. Please try again.','salesforce');
					}

				}else{

					$errors['recaptcha']['valid'] = false;

					if( isset( $options['recaptchaerrormsg'] ) && $options['recaptchaerrormsg'] ){
						$errors['recaptcha']['message'] = $options['recaptchaerrormsg'];
					}else{
						//backwards compatibility
						$errors['recaptcha']['message'] = __('Please complete the ReCaptcha field.','salesforce');
					}

				}

			}else{

				if( $_POST['captcha_hash'] != sha1( $_POST['captcha_text'].NONCE_SALT )){
					$has_error = true;

					$errors['captcha']['valid'] = false;

					if( isset( $options['captchaerrormsg'] ) && $options['captchaerrormsg'] ){
						$errors['captcha']['message'] = $options['captchaerrormsg'];
					}else{
						//backwards compatibility
						$errors['captcha']['message'] = __('The text you entered did not match the image.','salesforce');
					}

				}

			}

		}

		foreach( $errors as $error ){
			if(!$error['valid'])
				$has_error = true;
		}

/*
		$org_id = salesforce_get_option('org_id', $form_id, $options);
		echo '$org_id='.$org_id;
*/

		if (!$has_error) {
			$result = submit_salesforce_form($post, $options, $form);

			//echo 'RESULT='.$result;
			//if($result) echo 'true';
			//if(!$result) echo 'false';

			if (!$result){
				$content = '<strong class="error_message">'.esc_html(stripslashes($options['sferrormsg'])).'</strong>';
			}else{

				// Return / Success URL
				$returl = apply_filters( 'salesforce_w2l_returl', $options['forms'][$form]['returl'], $form );
				$returl = apply_filters( 'salesforce_w2l_returl_'.absint( $form_id ), $returl, $form );
				$returl = esc_url_raw( $returl );

				if( $returl ){
					?>
					<script type="text/javascript">
				   <!--
				      window.location= <?php echo "'" . $returl . "'"; ?>;
				   //-->
				   </script>
					<?php
				}

				// Success message
				$success_message = apply_filters( 'salesforce_w2l_success_message', salesforce_get_option( 'successmsg', $form, $options ), $form );
				$success_message = apply_filters( 'salesforce_w2l_success_message_'.absint( $form_id ), $success_message, $form );

				if( $success_message )
					$content = '<strong class="success_message">'.esc_html( stripslashes( $success_message ) ).'</strong>';

			}

			$sf_form_id = get_salesforce_form_id( $form_id, $sidebar );

			$content = '<div id="'.$sf_form_id.'">'.$content.'</div>';

		} else {
			$errormsg = esc_html( stripslashes($options['errormsg']) ) ;

			$content .= salesforce_form($options, $sidebar, $errors, $form);
		}
	} else {
		$content = salesforce_form($options, $sidebar, null, $form);
	}

	$layout = salesforce_get_option( 'layout', $form, $options );

	if( $layout ){
		$layout = 'sf_' . $layout;
	}

	return '<div class="salesforce_w2l_lead ' . sanitize_html_class( $layout ) . '">'.$content.'</div>';

}

Code file location:

salesforce-wordpress-to-lead/salesforce-wordpress-to-lead/salesforce.php

Conclusion

Now that you’ve learned how to embed the Brilliant Web-to-Lead for Salesforce 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 *