| 1 |
<?php |
| 2 |
|
| 3 |
namespace BitCode\BitForm\Frontend\Form\View\Theme\Fields; |
| 4 |
|
| 5 |
use BitCode\BitForm\Core\Util\FrontendHelpers; |
| 6 |
|
| 7 |
class InputWrapper |
| 8 |
{ |
| 9 |
private $_fieldData; |
| 10 |
private $_fieldKey; |
| 11 |
private $_fieldName; |
| 12 |
private $_formID; |
| 13 |
private $_error; |
| 14 |
private $_value; |
| 15 |
private $_fieldHelpers; |
| 16 |
|
| 17 |
public function __construct($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null) |
| 18 |
{ |
| 19 |
$this->_fieldData = $field; |
| 20 |
$this->_fieldKey = $rowID; |
| 21 |
$this->_fieldName = $field_name; |
| 22 |
$this->_formID = $formID; |
| 23 |
$this->_error = $error; |
| 24 |
$this->_value = $value; |
| 25 |
$this->_fieldHelpers = new FieldHelpers($field, $rowID, $form_atomic_Cls_map); |
| 26 |
} |
| 27 |
|
| 28 |
public function wrapper($field, $noLabel = false, $noErrMsg = false) |
| 29 |
{ |
| 30 |
$labelWrapper = !$noLabel ? $this->labelWrapper() : ''; |
| 31 |
$helperText = $this->helperText(); |
| 32 |
$error = !$noErrMsg ? $this->errorMessages() : ''; |
| 33 |
$inputWrapper = <<<INPUTWRAPPER |
| 34 |
<div |
| 35 |
{$this->_fieldHelpers->getCustomAttributes('fld-wrp')} |
| 36 |
class="{$this->_fieldHelpers->getAtomicCls('fld-wrp')} {$this->_fieldHelpers->getCustomClasses('fld-wrp')}" |
| 37 |
> |
| 38 |
{$labelWrapper} |
| 39 |
<div |
| 40 |
{$this->_fieldHelpers->getCustomAttributes('inp-wrp')} |
| 41 |
class="{$this->_fieldHelpers->getAtomicCls('inp-wrp')} {$this->_fieldHelpers->getCustomClasses('inp-wrp')}" |
| 42 |
> |
| 43 |
{$field} |
| 44 |
{$helperText} |
| 45 |
{$error} |
| 46 |
</div> |
| 47 |
</div> |
| 48 |
INPUTWRAPPER; |
| 49 |
|
| 50 |
return $inputWrapper; |
| 51 |
} |
| 52 |
|
| 53 |
private function labelWrapper() |
| 54 |
{ |
| 55 |
$_label = ''; |
| 56 |
$_lblPreIcn = $this->_fieldHelpers->icon('lblPreIcn', 'lbl-pre-i'); |
| 57 |
$_lblSufIcn = $this->_fieldHelpers->icon('lblSufIcn', 'lbl-suf-i'); |
| 58 |
$_reqPre = ''; |
| 59 |
$_reqPost = ''; |
| 60 |
$_lbl = ''; |
| 61 |
$_subtitle = ''; |
| 62 |
$_subtitleText = ''; |
| 63 |
$_subtitlePreIcn = $this->_fieldHelpers->icon('subTlePreIcn', 'sub-titl-pre-i'); |
| 64 |
$_subtitlePostIcn = $this->_fieldHelpers->icon('subTleSufIcn', 'sub-titl-suf-i'); |
| 65 |
if (property_exists($this->_fieldData, 'lbl')) { |
| 66 |
$replaceToBackSlash = $this->_fieldHelpers->replaceToBackSlash($this->_fieldData->lbl); |
| 67 |
$_lbl = wp_kses_post($this->_fieldHelpers->renderHTMR($replaceToBackSlash)); |
| 68 |
} |
| 69 |
|
| 70 |
if (property_exists($this->_fieldData, 'subtitle')) { |
| 71 |
$replaceToBackSlash = $this->_fieldHelpers->replaceToBackSlash($this->_fieldData->subtitle); |
| 72 |
$_subtitleText = wp_kses_post($this->_fieldHelpers->renderHTMR($replaceToBackSlash)); |
| 73 |
} |
| 74 |
|
| 75 |
// for pre required icon |
| 76 |
if ( |
| 77 |
$this->_fieldHelpers->property_exists_nested($this->_fieldData, 'valid->req') |
| 78 |
&& $this->_fieldHelpers->property_exists_nested($this->_fieldData, 'valid->reqShow', true) |
| 79 |
&& $this->_fieldHelpers->property_exists_nested($this->_fieldData, 'valid->reqPos', 'before') |
| 80 |
) { |
| 81 |
$_reqPre = <<<REQPRE |
| 82 |
<span |
| 83 |
{$this->_fieldHelpers->getCustomAttributes('req-smbl')} |
| 84 |
class="{$this->_fieldHelpers->getAtomicCls('req-smbl')} {$this->_fieldHelpers->getCustomClasses('req-smbl')}" |
| 85 |
> |
| 86 |
* |
| 87 |
</span> |
| 88 |
REQPRE; |
| 89 |
} |
| 90 |
// for post required icon |
| 91 |
if ( |
| 92 |
$this->_fieldHelpers->property_exists_nested($this->_fieldData, 'valid->req') |
| 93 |
&& $this->_fieldHelpers->property_exists_nested($this->_fieldData, 'valid->reqShow', true) |
| 94 |
&& $this->_fieldHelpers->property_exists_nested($this->_fieldData, 'valid->reqPos', 'before', 1) |
| 95 |
) { |
| 96 |
$_reqPost = <<<REQPOST |
| 97 |
<span |
| 98 |
{$this->_fieldHelpers->getCustomAttributes('req-smbl')} |
| 99 |
class="{$this->_fieldHelpers->getAtomicCls('req-smbl')} {$this->_fieldHelpers->getCustomClasses('req-smbl')}" |
| 100 |
> |
| 101 |
* |
| 102 |
</span> |
| 103 |
REQPOST; |
| 104 |
} |
| 105 |
|
| 106 |
// for Label |
| 107 |
if ( |
| 108 |
property_exists($this->_fieldData, 'lbl') |
| 109 |
// && isset($this->_fieldData->valid->hideLbl) |
| 110 |
// && $this->_fieldData->valid->hideLbl !== true |
| 111 |
) { |
| 112 |
$bfFrontendFormIds = FrontendHelpers::$bfFrontendFormIds; |
| 113 |
$contentCount = count($bfFrontendFormIds); |
| 114 |
$_label = <<<LABEL |
| 115 |
<label |
| 116 |
{$this->_fieldHelpers->getCustomAttributes('lbl')} |
| 117 |
class="{$this->_fieldHelpers->getAtomicCls('lbl')} {$this->_fieldHelpers->getCustomClasses('lbl')}" |
| 118 |
for="{$this->_fieldKey}-{$contentCount}"> |
| 119 |
{$_reqPre} |
| 120 |
{$_lblPreIcn} |
| 121 |
{$_lbl} |
| 122 |
{$_lblSufIcn} |
| 123 |
{$_reqPost} |
| 124 |
</label> |
| 125 |
LABEL; |
| 126 |
} |
| 127 |
|
| 128 |
// for subtitle |
| 129 |
if (property_exists($this->_fieldData, 'subtitle') && $this->_fieldData->subtitleHide) { |
| 130 |
$_subtitle = <<<SUBTITLE |
| 131 |
<div |
| 132 |
{$this->_fieldHelpers->getCustomAttributes('sub-titl')} |
| 133 |
class="{$this->_fieldHelpers->getAtomicCls('sub-titl')} {$this->_fieldHelpers->getCustomClasses('sub-titl')}" |
| 134 |
> |
| 135 |
{$_subtitlePreIcn} |
| 136 |
{$_subtitleText} |
| 137 |
{$_subtitlePostIcn} |
| 138 |
</div> |
| 139 |
SUBTITLE; |
| 140 |
} |
| 141 |
return <<<LABELWRAPPER |
| 142 |
<div |
| 143 |
{$this->_fieldHelpers->getCustomAttributes('lbl-wrp')} |
| 144 |
class="{$this->_fieldHelpers->getAtomicCls('lbl-wrp')} {$this->_fieldHelpers->getCustomClasses('lbl-wrp')}" |
| 145 |
> |
| 146 |
{$_label} |
| 147 |
{$_subtitle} |
| 148 |
</div> |
| 149 |
LABELWRAPPER; |
| 150 |
} |
| 151 |
|
| 152 |
private function helperText() |
| 153 |
{ |
| 154 |
$_helperTxtPreIcn = $this->_fieldHelpers->icon('hlpPreIcn', 'hlp-txt-pre-i'); |
| 155 |
$_helperTxtSufIcn = $this->_fieldHelpers->icon('hlpSufIcn', 'hlp-txt-suf-i'); |
| 156 |
$_helperTxt = ''; |
| 157 |
|
| 158 |
if (isset($this->_fieldData->helperTxt)) { |
| 159 |
$_helperTxt = wp_kses_post($this->_fieldHelpers->renderHTMR($this->_fieldData->helperTxt)); |
| 160 |
} |
| 161 |
|
| 162 |
if (property_exists($this->_fieldData, 'helperTxt') && $this->_fieldData->helperTxt) { |
| 163 |
$_helperTxt = <<<HELPERTEXT |
| 164 |
<div |
| 165 |
{$this->_fieldHelpers->getCustomAttributes('hlp-txt')} |
| 166 |
class="{$this->_fieldHelpers->getAtomicCls('hlp-txt')} {$this->_fieldHelpers->getCustomClasses('hlp-txt')}" |
| 167 |
> |
| 168 |
{$_helperTxtPreIcn} |
| 169 |
{$_helperTxt} |
| 170 |
{$_helperTxtSufIcn} |
| 171 |
</div> |
| 172 |
HELPERTEXT; |
| 173 |
} |
| 174 |
|
| 175 |
// for helper text |
| 176 |
return $_helperTxt; |
| 177 |
} |
| 178 |
|
| 179 |
public function errorMessages() |
| 180 |
{ |
| 181 |
$_errorPreIcn = $this->_fieldHelpers->icon('errPreIcn', 'err-txt-pre-i'); |
| 182 |
$_errorSufIcn = $this->_fieldHelpers->icon('errSufIcn', 'err-txt-suf-i'); |
| 183 |
$_error = ''; |
| 184 |
$_style = 'opacity: 0 !important; height: 0px !important;'; |
| 185 |
|
| 186 |
if ($this->_error) { |
| 187 |
$_error = wp_kses_post($this->_error); |
| 188 |
$_style = 'margin-top: 5px !important; height: 9px !important;'; |
| 189 |
} |
| 190 |
|
| 191 |
$errMsgStart = ''; |
| 192 |
$errMsgEnd = ''; |
| 193 |
$msgStyle = "style='display: none !important;'"; |
| 194 |
$errMsgAtomicCls = $this->_fieldHelpers->getAtomicCls('err-msg'); |
| 195 |
$errMsgCustomCls = $this->_fieldHelpers->getCustomClasses('err-msg'); |
| 196 |
$errMsgCustomAttr = $this->_fieldHelpers->getCustomAttributes('err-msg'); |
| 197 |
if (!(empty($_errorPreIcn) && empty($_errorSufIcn))) { |
| 198 |
$errMsgStart = "<div {$errMsgCustomAttr} class='{$errMsgAtomicCls} {$errMsgCustomCls}' {$msgStyle}>"; |
| 199 |
$errMsgEnd = '</div>'; |
| 200 |
$msgStyle = ''; |
| 201 |
$errMsgAtomicCls = ''; |
| 202 |
$errMsgCustomCls = ''; |
| 203 |
$errMsgCustomAttr = ''; |
| 204 |
} |
| 205 |
|
| 206 |
return <<<ERRORMESSAGES |
| 207 |
<div class='{$this->_fieldHelpers->getAtomicCls('err-wrp')}' style="{$_style}"> |
| 208 |
<div class='{$this->_fieldHelpers->getAtomicCls('err-inner')}'> |
| 209 |
{$errMsgStart} |
| 210 |
{$_errorPreIcn} |
| 211 |
<div {$this->_fieldHelpers->getCustomAttributes('err-txt')} {$errMsgCustomAttr} class="{$errMsgAtomicCls} {$errMsgCustomCls} {$this->_fieldHelpers->getAtomicCls('err-txt')} {$this->_fieldHelpers->getCustomClasses('err-txt')}" {$msgStyle}>{$_error}</div> |
| 212 |
{$_errorSufIcn} |
| 213 |
{$errMsgEnd} |
| 214 |
</div> |
| 215 |
</div> |
| 216 |
ERRORMESSAGES; |
| 217 |
} |
| 218 |
} |
| 219 |
|