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