# bit-form/2.9.1/includes/Core/Fallback/StylesFallback.php

Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator &amp; Custom Form Builder, version 2.9.1. 128 lines.

- Page: https://pluginprobe.com/plugins/bit-form/2.9.1/code/includes/Core/Fallback/StylesFallback.php
- Raw: https://pluginprobe.com/plugins/bit-form/2.9.1/raw/includes/Core/Fallback/StylesFallback.php
- Modified: 2023-12-16T11:37:40+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/bit-form/2.9.1/code/includes/Core/Fallback/StylesFallback.php#L10-L20`.

```php
<?php

namespace BitCode\BitForm\Core\Fallback;

use BitCode\BitForm\Core\Database\FormModel;
use BitCode\BitForm\Core\Util\Utilities;
use Jcof\Jcof;

class StylesFallback
{
  public function stripeFldButtonDisabled()
  {
    $stylesArray = [
      '.__fk__-stripe-btn:disabled' => [
        'background' => '#7ca5e7',
        'transform'  => 'none',
      ],
      '.__fk__-stripe-wrp .stripe-pay-btn:disabled'=> [
        'background' => '#7ca5e7',
        'transform'  => 'none',
      ]
    ];

    $this->addStyles('stripe', $stylesArray);
  }

  /**
   *  for adding fallback styles to field in form staticStyles object
   *
   * @param string $fieldType
   * @param array $stylesArray
   * @return void
   */
  private function addStyles(string $fieldType, array $stylesArray): void
  {
    $formModel = new FormModel();
    $forms = $formModel->get(
      ['id', 'form_content', 'builder_helper_state']
    );

    if (is_wp_error($forms)) {
      return;
    }
    foreach ($forms as $form) {
      $hasStyleChanged = false;
      $formId = $form->id;
      $builderHelperState = json_decode($form->builder_helper_state);
      if (empty($builderHelperState->staticStyles)) {
        continue;
      }
      $staticStyleState = $builderHelperState->staticStyles;
      $staticStyleState = Jcof::parse($staticStyleState);

      $formContent = json_decode($form->form_content);
      $fields = $formContent->fields;

      foreach ($fields as $fldKey => $fldData) {
        if ($fieldType !== $fldData->typ) {
          continue;
        }
        if (!isset($staticStyleState['staticStyles'])) {
          $staticStyleState['staticStyles'] = [];
        }

        $newStyles = $this->replaceFldKey($fldKey, $stylesArray);

        foreach ($newStyles as $newStyleKey => $newStyleValue) {
          $staticStyleState['staticStyles'][$newStyleKey] = $newStyleValue;
        }
        
        $generatedStyleCSS = Utilities::styleGenerator($newStyles);
        Utilities::appendCSS($formId, $generatedStyleCSS);
        $hasStyleChanged = true;
      }

      if (!$hasStyleChanged) {
        continue;
      }

      $staticStyleState = Jcof::stringify($staticStyleState);
      $builderHelperState->staticStyles = $staticStyleState;
      $formModel->update(
        [
          'builder_helper_state' => wp_json_encode($builderHelperState),
        ],
        [
          'id' => $formId,
        ]
      );
    }
  }

  /**
   * @method for replacing __fk__ with field key in styles array keys
   * @example: .__fk__-stripe-btn:disabled to .bk-1-stripe-btn:disabled
   * 
   * @param string $fldKey
   * @param array $stylesArray
   * @return array $newStyleArray
   */
  private function replaceFldKey(string $fldKey, array $stylesArray): array
  {
    $newStyleArray = [];
    foreach ($stylesArray as $key => $value) {
      $key = str_replace('__fk__', $fldKey, $key);
      $newStyleArray[$key] = $value;
    }
    return $newStyleArray;
  }

  public function signatureFldIframeStyle()
  {
    $signatureIframeStyle = [
      '.__fk__-signature-iframe' => [
        'position'      => 'absolute',
        'top'           => 0,
        'left'          => 0,
        'width'         => '100%',
        'height'        => '100%',
        'opacity'       => 0,
        'pointer-events'=> 'none',
        'border'        => 'none',
      ]
    ];

    $this->addStyles('signature', $signatureIframeStyle);
  }
}
```
