| 1 |
<?php |
| 2 |
|
| 3 |
namespace BitCode\BitForm\Frontend\Form\View\Theme; |
| 4 |
|
| 5 |
use BitCode\BitForm\Frontend\Form\View\Theme\Fields\AdvanceFileUpField; |
| 6 |
use BitCode\BitForm\Frontend\Form\View\Theme\Fields\ButtonField; |
| 7 |
use BitCode\BitForm\Frontend\Form\View\Theme\Fields\CheckBoxField; |
| 8 |
use BitCode\BitForm\Frontend\Form\View\Theme\Fields\CountryField; |
| 9 |
use BitCode\BitForm\Frontend\Form\View\Theme\Fields\CurrencyField; |
| 10 |
use BitCode\BitForm\Frontend\Form\View\Theme\Fields\DecisionBoxField; |
| 11 |
use BitCode\BitForm\Frontend\Form\View\Theme\Fields\DividerField; |
| 12 |
use BitCode\BitForm\Frontend\Form\View\Theme\Fields\DropdownField; |
| 13 |
use BitCode\BitForm\Frontend\Form\View\Theme\Fields\FileUploadField; |
| 14 |
use BitCode\BitForm\Frontend\Form\View\Theme\Fields\HTMLField; |
| 15 |
use BitCode\BitForm\Frontend\Form\View\Theme\Fields\HtmlSelectField; |
| 16 |
use BitCode\BitForm\Frontend\Form\View\Theme\Fields\ImageField; |
| 17 |
use BitCode\BitForm\Frontend\Form\View\Theme\Fields\ImageSelectField; |
| 18 |
use BitCode\BitForm\Frontend\Form\View\Theme\Fields\PayPalField; |
| 19 |
use BitCode\BitForm\Frontend\Form\View\Theme\Fields\PhoneNumberField; |
| 20 |
use BitCode\BitForm\Frontend\Form\View\Theme\Fields\RadioBoxField; |
| 21 |
use BitCode\BitForm\Frontend\Form\View\Theme\Fields\RatingField; |
| 22 |
use BitCode\BitForm\Frontend\Form\View\Theme\Fields\RazorPayField; |
| 23 |
use BitCode\BitForm\Frontend\Form\View\Theme\Fields\RecaptchaV2Field; |
| 24 |
use BitCode\BitForm\Frontend\Form\View\Theme\Fields\RepeaterField; |
| 25 |
use BitCode\BitForm\Frontend\Form\View\Theme\Fields\SectionField; |
| 26 |
use BitCode\BitForm\Frontend\Form\View\Theme\Fields\SignatureField; |
| 27 |
use BitCode\BitForm\Frontend\Form\View\Theme\Fields\StripeField; |
| 28 |
use BitCode\BitForm\Frontend\Form\View\Theme\Fields\TextAreaField; |
| 29 |
use BitCode\BitForm\Frontend\Form\View\Theme\Fields\TextField; |
| 30 |
use BitCode\BitForm\Frontend\Form\View\Theme\Fields\TitleField; |
| 31 |
use BitCode\BitForm\Frontend\Form\View\Theme\Fields\TurnstileField; |
| 32 |
|
| 33 |
class ThemeBase |
| 34 |
{ |
| 35 |
private $_nestedLayout; |
| 36 |
private $_formViewerInstance; |
| 37 |
|
| 38 |
public function inputWrapper($formViewInstance, $rowID) |
| 39 |
{ |
| 40 |
$field = $formViewInstance->fields($rowID); |
| 41 |
$field_name = $formViewInstance->getFieldName($rowID); |
| 42 |
$form_atomic_Cls_map = $formViewInstance->getAtomicClaMap(); |
| 43 |
$error = $formViewInstance->getError($rowID); |
| 44 |
$value = $formViewInstance->getValue($field_name, $rowID); |
| 45 |
$formID = $formViewInstance->getFormID(); |
| 46 |
$this->_nestedLayout = $formViewInstance->getNestedLayout($rowID); |
| 47 |
$this->_formViewerInstance = $formViewInstance; |
| 48 |
|
| 49 |
// $isHidden = !empty($field->valid->hide) && $field->valid->hide ? 'vis-n' : null; |
| 50 |
$isHidden = !empty($field->valid->hide) && $field->valid->hide ? 'fld-hide' : null; |
| 51 |
// $isReqSym = empty($field->valid->req) ? null : ' <span class="fld-req-symbol">*</span>'; |
| 52 |
// $noLabel = ['decision-box', 'html', 'button', 'paypal', 'razorpay', 'recaptcha']; |
| 53 |
// $fieldLbl = ""; |
| 54 |
|
| 55 |
// if (!in_array($field->typ, $noLabel) && isset($field->lbl)) { |
| 56 |
// $replaceToBackslash = str_replace('$_bf_$', '\\', $field->lbl); |
| 57 |
// $fieldLbl = FieldValueHandler::replaceSmartTagWithValue($replaceToBackslash); |
| 58 |
// } |
| 59 |
|
| 60 |
// if (isset($field->ph)) { |
| 61 |
// $phReplaceToBackslash = str_replace('$_bf_$', '\\', $field->ph); |
| 62 |
// $field->ph = FieldValueHandler::replaceSmartTagWithValue($phReplaceToBackslash); |
| 63 |
// } |
| 64 |
|
| 65 |
// $lbl = (!in_array($field->typ, $noLabel) && !isset($field->valid->hideLbl) && isset($field->lbl)) ? "<label class='fld-lbl fld-lbl-$formID' for='$rowID'>" . esc_html($fieldLbl) . $isReqSym . "</label>" : ""; |
| 66 |
|
| 67 |
// $err = (isset($error) && !empty($error)) ? $error : ""; |
| 68 |
// $errStyle = !empty($err) ? "style='height: auto'" : ""; |
| 69 |
$fieldHTML = $this->getField($field, $rowID, $field_name, $form_atomic_Cls_map, $error, $value, $formID); |
| 70 |
// $errHTML = ''; |
| 71 |
// if ($err || isset($field->err)) { |
| 72 |
// $errHTML = <<<ERRORHTML |
| 73 |
// <div class="error-wrapper" $errStyle> |
| 74 |
// <div id="$rowID-error" class="error-txt">$err</div> |
| 75 |
// </div> |
| 76 |
// ERRORHTML; |
| 77 |
// } |
| 78 |
|
| 79 |
return <<<INPUTWRAPPER |
| 80 |
<div class="btcd-fld-itm $rowID $isHidden"> |
| 81 |
$fieldHTML |
| 82 |
</div> |
| 83 |
INPUTWRAPPER; |
| 84 |
|
| 85 |
// return $fieldHTML; |
| 86 |
} |
| 87 |
|
| 88 |
protected function getField($field, $rowID, $field_name, $form_atomic_Cls_map, $error = null, $value = null, $formID = null) |
| 89 |
{ |
| 90 |
switch ($field->typ) { |
| 91 |
case 'text': |
| 92 |
case 'username': |
| 93 |
case 'number': |
| 94 |
case 'password': |
| 95 |
case 'email': |
| 96 |
case 'url': |
| 97 |
case 'date': |
| 98 |
case 'datetime-local': |
| 99 |
case 'time': |
| 100 |
case 'month': |
| 101 |
case 'week': |
| 102 |
case 'color': |
| 103 |
return TextField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 104 |
case 'textarea': |
| 105 |
return TextAreaField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 106 |
case 'check': |
| 107 |
// return $this->checkBox($field, $rowID, $field_name, $formID, $error, $value); |
| 108 |
return CheckBoxField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 109 |
case 'radio': |
| 110 |
// return $this->radioBox($field, $rowID, $field_name, $formID, $error, $value); |
| 111 |
return RadioBoxField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 112 |
case 'html-select': |
| 113 |
return HtmlSelectField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 114 |
case 'select': |
| 115 |
// return $this->dropDown($field, $rowID, $field_name, $formID, $error, $value); |
| 116 |
return DropdownField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 117 |
case 'file-up': |
| 118 |
// return $this->fileUp($field, $rowID, $field_name, $formID, $error, $value); |
| 119 |
return FileUploadField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 120 |
case 'recaptcha': |
| 121 |
return RecaptchaV2Field::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 122 |
case 'turnstile': |
| 123 |
return TurnstileField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 124 |
case 'decision-box': |
| 125 |
// return $this->decisionBox($field, $rowID, $field_name, $formID, $error, $value); |
| 126 |
return DecisionBoxField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 127 |
case 'html': |
| 128 |
// return $this->html($field, $rowID, $field_name, $formID, $error, $value); |
| 129 |
return HTMLField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 130 |
case 'paypal': |
| 131 |
return PayPalField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 132 |
case 'stripe': |
| 133 |
return StripeField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 134 |
case 'razorpay': |
| 135 |
// return $this->razorPay($field, $rowID, $field_name, $formID, $error, $value); |
| 136 |
return RazorPayField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 137 |
// case 'submit': |
| 138 |
// return $this->submitBtns($field, $rowID, $field_name, $formID, $error, $value); |
| 139 |
case 'button': |
| 140 |
// return $this->button($field, $rowID, $field_name, $formID, $error, $value); |
| 141 |
return ButtonField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 142 |
case 'title': |
| 143 |
// return $this->button($field, $rowID, $field_name, $formID, $error, $value); |
| 144 |
return TitleField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 145 |
case 'divider': |
| 146 |
// return $this->button($field, $rowID, $field_name, $formID, $error, $value); |
| 147 |
return DividerField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 148 |
case 'country': |
| 149 |
return CountryField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 150 |
case 'currency': |
| 151 |
return CurrencyField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 152 |
case 'phone-number': |
| 153 |
return PhoneNumberField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 154 |
case 'advanced-file-up': |
| 155 |
return AdvanceFileUpField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 156 |
case 'image': |
| 157 |
return ImageField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 158 |
case 'section': |
| 159 |
return SectionField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $this->_formViewerInstance, $this->_nestedLayout, $error, $value); |
| 160 |
case 'repeater': |
| 161 |
return RepeaterField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $this->_formViewerInstance, $this->_nestedLayout, $error, $value); |
| 162 |
case 'signature': |
| 163 |
return SignatureField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 164 |
case 'rating': |
| 165 |
return RatingField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 166 |
case 'image-select': |
| 167 |
return ImageSelectField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 168 |
default: |
| 169 |
break; |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
protected function setTag($tag, $value, $attr = null) |
| 174 |
{ |
| 175 |
echo "<$tag $attr>" . esc_html($value) . "</$tag>"; |
| 176 |
} |
| 177 |
|
| 178 |
protected function setAttribute($attr, $value = null) |
| 179 |
{ |
| 180 |
echo " $attr='" . esc_attr($value) . "' "; |
| 181 |
} |
| 182 |
|
| 183 |
protected function setSingleValuedAttribute($attr) |
| 184 |
{ |
| 185 |
echo " $attr "; |
| 186 |
} |
| 187 |
} |
| 188 |
|