Bit Form Shortcodes

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

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

Plugin Icon
Contact Form Builder by Bit Form – Easiest Multi Step Contact Form, Payment Form, Calculator Form Builder Plugin for WordPress

"Contact Form Builder by Bit Form is a versatile WordPress plugin. Easily create multi-step contact forms, payment forms and calculator forms. Simplify user interaction and data collection on your website."

★★★★☆ (49) Active Installs: 2000+ Tested with: 6.3.2 PHP Version: 5.6
Included Shortcodes:
  • [bitforms-frontend-file]
  • [bitform]

Bit Form [bitforms-frontend-file] Shortcode

The BitForms Frontend File shortcode is a functional tool in PHP coding. It handles file downloads in WordPress by checking if the formID, entryID, and fileID are set. If these are not set, it will return a 404 error. It also sanitizes the input for security. If the file path is readable, it initiates the file download or view. This shortcode ensures secure and efficient file handling.

Shortcode: [bitforms-frontend-file]

Parameters

Here is a list of all possible bitforms-frontend-file shortcode parameters and attributes:

  • formID – The unique identifier of the form
  • entryID – The unique identifier of the entry in the form
  • fileID – The unique identifier of the file to be downloaded

Examples and Usage

Basic example – A simple shortcode usage to download a file using the form ID, entry ID, and file ID.

[bitforms-frontend-file formID=1 entryID=2 fileID="sample.pdf" /]

Advanced examples

In this advanced example, we are using the shortcode to download a file using the form ID, entry ID, and file ID. However, if the file is not found, a 404 error page will be displayed.

[bitforms-frontend-file formID=3 entryID=4 fileID="notfound.pdf" /]

In another advanced example, we are using a different form ID and entry ID to download a different file.

[bitforms-frontend-file formID=5 entryID=6 fileID="different.pdf" /]

Note that in all these examples, the formID, entryID, and fileID are parameters that you need to replace with actual values based on your use case. The formID and entryID should be integers, while the fileID should be the name of the file you want to download.

PHP Function Code

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

Shortcode line:

add_shortcode('bitforms-frontend-file', [$this, 'handleFileDownload']);

Shortcode PHP function:

function handleFileDownload()
  {
    if (!isset($_GET['formID']) || !isset($_GET['entryID']) || !isset($_GET['fileID'])) {
      global $wp_query;
      $wp_query->set_404();
      status_header(404);
      get_template_part(404);
      exit();
    }
    $formID = intval(sanitize_text_field($_GET['formID']));
    $entryID = intval(sanitize_text_field($_GET['entryID']));
    $fileID = sanitize_file_name($_GET['fileID']);
    $filePath = BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID . DIRECTORY_SEPARATOR . $entryID . DIRECTORY_SEPARATOR . $fileID;
    if (is_readable($filePath)) {
      $this->fileDownloadORView($filePath, true);
    }
  }

Code file location:

bit-form/bit-form/includes/Core/Util/FileDownloadProvider.php

Bit Form [bitform] Shortcode

The Bitform shortcode is a powerful tool that manages the rendering of forms on the frontend. It allows users to insert specific forms into their posts or pages using a unique form ID. The shortcode also checks if the form exists, is active, and handles form abandonment. It sets up Google reCAPTCHA, handles field values, and manages form layouts. It also validates form fields on focus loss and maintains step history for multi-step forms.

Shortcode: [bitform]

Parameters

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

  • form_id – Identifies the specific form to be used
  • entry_id – Identifies the specific entry in the form
  • id – Another way to identify the specific form to be used
  • form_preview – When set, allows the form to be previewed before submission

Examples and Usage

Basic example – Display a Bit-form by referencing its ID.

[bitform form_id=1 /]

Advanced example 1 – Display a Bit-form by referencing its ID and also provide an entry ID. The form will first try to load by form ID and then load the specific entry by its ID.

[bitform form_id=1 entry_id=2 /]

Advanced example 2 – Display a Bit-form by referencing its ID and preview the form. The form will load by form ID and it will be in preview mode.

[bitform form_id=1 form_preview=true /]

Advanced example 3 – Display a Bit-form by referencing its ID and also provide a different ID. The form will first try to load by form ID, but if not found, it will try to load by the alternative ID.

[bitform form_id=1 id=2 /]

PHP Function Code

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

Shortcode line:

add_shortcode('bitform', [$this, 'handleFrontendRenderRequest']);

Shortcode PHP function:

function handleFrontendRenderRequest($atts)
  {
    $formPreview = isset($atts['form_preview']) ? $atts['form_preview'] : false;
    if (isset($atts['form_id'])) {
      $formID = intval($atts['form_id']);
    }
    if (isset($atts['entry_id'])) {
      $entryId = intval($atts['entry_id']);
    } else {
      $entryId = false;
    }
    if (isset($atts['id'])) {
      $atts = shortcode_atts(['id' => 0], $atts);
      $formID = intval($atts['id']);
    }

    if (!$formID) {
      return __('Form ID cannot be empty', 'bit-form');
    }

    if (!$this->isExist($formID)) {
      return sprintf(__('#%s no. Form doesn\'t exists', 'bit-form'), $formID);
    }

    // check for abandoned form entry id
    $isAbandoned = false;
    if (empty($entryId) && Utilities::isPro() && class_exists('\BitCode\BitFormPro\Admin\FormSettings\FormAbandonment')) {
      $FormAbandonment = new FormAbandonment($formID);
      $isAbandoned = $FormAbandonment->checkAbandonedFormEntryId();
    }

    FrontendHelpers::setBfFrontendFormIds($formID);
    $bfFrontendFormIds = FrontendHelpers::$bfFrontendFormIds;
    $shortCodeCounter = count($bfFrontendFormIds);
    $FrontendFormManager = new FrontendFormManager($formID, $shortCodeCounter);

    if (!$FrontendFormManager->checkStatus()) {
      return  sprintf(__('#%s no. Form is not active', 'bit-form'), $formID);
    }
    ob_start();
    $this->loadAssets($formID);

    $font = $FrontendFormManager->getFont();

    if ($font && !$formPreview) {
      wp_enqueue_style('bf-google-font', $font, '1.0.0', true);
    }

    if (!empty($_GET['token']) && !empty($_GET['id'])) {
      $this->validPassowordResetToken($_GET['token'], $_GET['id'], $formID);
    }

    $previousValue = $this->getValuesFromQueryParams();
    $errorMessages = []; // delete
    $FormIdentifier = esc_js($FrontendFormManager->getFormIdentifier());
    $nonce = $FrontendFormManager->getFormToken();
    $file = count($FrontendFormManager->getUploadFields()) > 0 ? $FrontendFormManager->getUploadFields() : false;

    $FrontendFormManager->setViewCount();

    $formContent = $FrontendFormManager->getFormContentWithValue($previousValue);
    $fields = $formContent->fields;
    $layout = $formContent->layout;
    $nestedLayout = $formContent->nestedLayout;
    $buttons = !empty($formContent->buttons) ? $formContent->buttons : '';
    $additional = $formContent->additional;

    $workFlowRunType = $entryId ? 'edit' : 'create';
    if ($entryId) {
      $fields = $this->setFieldsValue($fields, $formID, $entryId);
    }

    $fields = $this->triggerWorkflowOnLoad($formID, $shortCodeCounter, $fields, $workFlowRunType);
    $workFlowreturnedOnUserInput = $this->executeOnUserInput($formID, $shortCodeCounter, $fields);

    // test for form before remove
    $noLabel = ['decision-box', 'html', 'button', 'paypal', 'razorpay', 'recaptcha'];
    foreach ($fields as $fldKey => $field) {
      if (!in_array($field->typ, $noLabel) && isset($field->lbl)) {
        $lblReplaceToBackslash = str_replace('$_bf_$', '\\', $field->lbl);
        $fields->{$fldKey}->lbl = FieldValueHandler::replaceSmartTagWithValue($lblReplaceToBackslash);
      }
    }
    $fieldsKey = $FrontendFormManager->getFieldsKey();

    $captchaV3Settings = $FrontendFormManager->getCaptchaV3Settings();
    if ($FrontendFormManager->getCaptchaSettings() || $captchaV3Settings) {
      $integrationHandler = new IntegrationHandler(0);
      $allFormIntegrations = $integrationHandler->getAllIntegration('app');
      if (!is_wp_error($allFormIntegrations)) {
        foreach ($allFormIntegrations as $integration) {
          if (
            $FrontendFormManager->getCaptchaSettings()
            && !is_null($integration->integration_type)
            && 'gReCaptcha' === $integration->integration_type
          ) {
            $integrationDetails = json_decode($integration->integration_details);
            $integrationDetails->id = $integration->id;
            $reCAPTCHA = $integrationDetails;
            $reCAPTCHAVersion = 'v2';
          }

          if ($captchaV3Settings) {
            if (!is_null($integration->integration_type) && 'gReCaptchaV3' === $integration->integration_type) {
              $integrationDetails = json_decode($integration->integration_details);
              $integrationDetails->id = $integration->id;
              $reCAPTCHA = $integrationDetails;
              $reCAPTCHAVersion = 'v3';
            }
          }
        }
      }
    }

    if ($captchaV3Settings && !empty($reCAPTCHA->siteKey)) {
      // DANGER: no matter what, DONT CHANGE THE SCRIPT ID OF THIS SCRIPT
      $scriptId = BITFORMS_PREFIX . 'recaptcha';
      wp_enqueue_script($scriptId, "https://www.google.com/recaptcha/api.js?render={$reCAPTCHA->siteKey}");
    }

    $configs = [
      'bf_separator' => BITFORMS_BF_SEPARATOR,
    ];

    // check if fields has paypal or razorpay
    $paymentFields = ['paypal', 'razorpay', 'stripe'];
    $paymentFieldData = [];
    foreach ($fields as $key => $field) {
      if (in_array($field->typ, $paymentFields)) {
        $paymentFieldData[$key] = $field;
      }
    }

    if (!empty($paymentFieldData)) {
      $integrationHandler = new IntegrationHandler(0);
      foreach ($paymentFieldData as $fldKey => $fldData) {
        if ('paypal' === $fldData->typ) {
          $paypalIntegration = $integrationHandler->getAIntegration($fldData->payIntegID);
          $integrationDetails = json_decode($paypalIntegration[0]->integration_details);
          $clientID = $integrationDetails->clientID;
          $fields->{$fldKey}->clientId = $clientID;
        } elseif ('razorpay' === $fldData->typ) {
          $razorpayIntegration = $integrationHandler->getAIntegration($fldData->payIntegID);
          $integrationDetails = json_decode($razorpayIntegration[0]->integration_details);
          $clientID = $integrationDetails->apiKey;
          $fields->{$fldKey}->clientId = $clientID;
        } elseif ('stripe' === $fldData->typ) {
          $stripeIntegration = $integrationHandler->getAIntegration($fldData->payIntegID);
          $integrationDetails = json_decode($stripeIntegration[0]->integration_details);
          $publishableKey = $integrationDetails->publishableKey;
          $fields->{$fldKey}->publishableKey = $publishableKey;
        }
      }
    }

    $bitFormFrontArr = [
      'ajaxURL'                        => admin_url('admin-ajax.php'),
      'nonce'                          => $nonce,
      'version'                        => BITFORMS_VERSION,
      'layout'                         => $layout,
      'nestedLayout'                   => $nestedLayout,
      'fields'                         => $fields,
      'buttons'                        => $buttons,
      'fieldsKey'                      => $fieldsKey,
      'file'                           => $file,
      'configs'                        => $configs,
      'formId'                         => $formID,
      'appID'                          => "bitforms_{$formID}",
      'GCLID'                          => $FrontendFormManager->isGCLIDEnabled(),
      'assetUrl'                       => BITFORMS_ASSET_URI,
      'onfieldCondition'               => !empty($workFlowreturnedOnUserInput['onfield_input_conditions']) ? $workFlowreturnedOnUserInput['onfield_input_conditions'] : false,
      'smartTags'                      => !empty($workFlowreturnedOnUserInput['smart_tags']) ? $workFlowreturnedOnUserInput['smart_tags'] : [],
      'paymentCallbackUrl'             => get_rest_url() . 'bitform/v1/payments/razorpay',
      'gRecaptchaSiteKey'              => !empty($reCAPTCHA->siteKey) ? $reCAPTCHA->siteKey : null,
      'gRecaptchaVersion'              => !empty($reCAPTCHAVersion) ? $reCAPTCHAVersion : null,
    ];

    if ($entryId) {
      $bitFormFrontArr['entryId'] = $entryId;
    }

    if (isset($additional->enabled->validateFocusLost)) {
      $bitFormFrontArr['validateFocusLost'] = true;
    }

    if (!empty($isAbandoned)) {
      $bitFormFrontArr['oldValues'] = $this->getFieldsValue($formID, $isAbandoned);
      if (empty($entryId)) {
        $bitFormFrontArr['entryId'] = $isAbandoned;
      }
    }

    if (is_array($layout) && count($layout) > 1) {
      $formInfo = $FrontendFormManager->getFormInfo();
      $multiStepSettings = isset($formInfo->multiStepSettings) ? $formInfo->multiStepSettings : null;
      $newTempSettings = (object) [
        'validateOnStepChange' => isset($multiStepSettings->validateOnStepChange) ? $multiStepSettings->validateOnStepChange : false,
        'maintainStepHistory'  => isset($multiStepSettings->maintainStepHistory) ? $multiStepSettings->maintainStepHistory : false,
        'saveProgress'         => isset($multiStepSettings->saveProgress) ? $multiStepSettings->saveProgress : false,
        'showPercentage'       => isset($multiStepSettings->progressSettings->showPercentage) ? $multiStepSettings->progressSettings->showPercentage : false,
      ];
      $bitFormFrontArr['formInfo'] = (object) [
        'multiStepSettings' => $newTempSettings
      ];
    }

    $bitFormsFront = apply_filters(
      'bitforms_localized_script',
      $bitFormFrontArr
    );

    $layout = \json_encode($layout);
    $buttons = \json_encode($buttons);
    $frontArr = json_encode($bitFormFrontArr);

    $bfGlobals = <<<BFGLOBALS
      if(!window.bf_globals) { 
        window.bf_globals = {} 
      } if(!window.bf_globals.{$FormIdentifier}) { 
        window.bf_globals.{$FormIdentifier} = {} 
      }
      if(document.getElementById('{$FormIdentifier}')) {
        window.bf_globals.{$FormIdentifier} = {...window.bf_globals.{$FormIdentifier}, ...{$frontArr}};
      }
BFGLOBALS;
    $this->addInlineScript($bfGlobals, 'bit-form-all-script', 'before');

    $html = $FrontendFormManager->formView($fields, $file, $errorMessages);

    // if form preview then return html otherwise echo with output buffer
    if ($formPreview) {
      ob_clean();
      $formViewObject = new \stdClass();
      $formViewObject->html = $html;
      $formViewObject->font = $font;
      $formViewObject->bfGlobals = $bfGlobals;
      return $formViewObject;
    }
    echo trim($html);
    return ob_get_clean();
  }

Code file location:

bit-form/bit-form/includes/Frontend/Form/FrontendFormHandler.php

Conclusion

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