| @@ -2,8 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace BitCode\BitForm\Frontend\Form\View; |
| 4 | 4 | |
| 5 | 5 | use BitCode\BitForm\Admin\Form\Helpers; |
| 6 | +use BitCode\BitForm\Core\Util\Translation\TranslationManager; | |
| 6 | 7 | use BitCode\BitForm\Frontend\Form\FrontendFormManager; |
| 7 | 8 | use BitCode\BitForm\Frontend\Form\View\Conversational\ConversationalHelpers; |
| 8 | 9 | use BitCode\BitForm\Frontend\Form\View\Conversational\DefaultConversationalTheme; |
| 9 | 10 | |
| @@ -56,17 +57,49 @@ | ||
| 56 | 57 | $honeypodFldName = Helpers::honeypotEncryptedToken("_bitforms_{$this->getFormID()}_{$time}_"); |
| 57 | 58 | $honeypotInput = ''; |
| 58 | 59 | if (Helpers::property_exists_nested($this->_formContents, 'additional->enabled->honeypot', true)) { |
| 59 | 60 | $honeypotInput = |
| 60 | - <<<HTMLa | |
| 61 | - <input type="text" class="d-none" name="b_h_t" value="{$honeypodFldName}"> | |
| 62 | - <input type="text" class="d-none" name="{$honeypodFldName}" required> | |
| 63 | -HTMLa; | |
| 61 | + ' | |
| 62 | + <input type="text" class="d-none" name="b_h_t" value="' . $honeypodFldName . '"> | |
| 63 | + <input type="text" class="d-none" name="' . $honeypodFldName . '" required> | |
| 64 | + '; | |
| 64 | 65 | return $honeypotInput; |
| 65 | 66 | } |
| 66 | 67 | return $honeypotInput; |
| 67 | 68 | } |
| 68 | 69 | |
| 70 | + /** | |
| 71 | + * Opt-out markers for HTML-layer translators (Google/GTranslate, TranslatePress) | |
| 72 | + * when a form disables translation. Empty otherwise, so markup is untouched. | |
| 73 | + * | |
| 74 | + * @return array{attrs:string, cls:string} | |
| 75 | + */ | |
| 76 | + private function noTranslateMarkup() | |
| 77 | + { | |
| 78 | + // Pass the row we already hold; otherwise the lookup re-queries form_content per render. | |
| 79 | + $rawContent = $this->_form->isExist() ? $this->_form->getFieldsContent() : null; | |
| 80 | + $enabled = TranslationManager::isFormTranslationEnabled($this->getFormID(), $rawContent); | |
| 81 | + if ($enabled) { | |
| 82 | + return ['attrs' => '', 'cls' => '']; | |
| 83 | + } | |
| 84 | + return ['attrs' => ' translate="no" data-no-translation', 'cls' => ' notranslate']; | |
| 85 | + } | |
| 86 | + | |
| 87 | + /** | |
| 88 | + * Carries the page language into the AJAX submission so validation and | |
| 89 | + * confirmation strings match it. Empty when no provider resolves one. | |
| 90 | + * | |
| 91 | + * @return string | |
| 92 | + */ | |
| 93 | + private function languageField() | |
| 94 | + { | |
| 95 | + $lang = (string) apply_filters('bitform_current_language', '', $this->getFormID()); | |
| 96 | + if ('' === $lang) { | |
| 97 | + return ''; | |
| 98 | + } | |
| 99 | + return '<input type="text" class="d-none" name="bf_lang" value="' . esc_attr($lang) . '">'; | |
| 100 | + } | |
| 101 | + | |
| 69 | 102 | public function setTheme($theme = 'Default') |
| 70 | 103 | { |
| 71 | 104 | $this->_theme = $theme; |
| 72 | 105 | } |
| @@ -122,9 +155,9 @@ | ||
| 122 | 155 | } |
| 123 | 156 | |
| 124 | 157 | public function fields($rowID) |
| 125 | 158 | { |
| 126 | - return $this->_fields->{$rowID}; | |
| 159 | + return $this->_fields->{$rowID} ?? null; | |
| 127 | 160 | } |
| 128 | 161 | |
| 129 | 162 | public function getNestedLayout($rowID) |
| 130 | 163 | { |
| @@ -147,8 +180,9 @@ | ||
| 147 | 180 | } |
| 148 | 181 | |
| 149 | 182 | public function getConversationalView($hasFile, $msg = null) |
| 150 | 183 | { |
| 184 | + $noTranslate = $this->noTranslateMarkup(); | |
| 151 | 185 | $conversationSettings = $this->getFormInfo()->conversationalSettings; |
| 152 | 186 | $this->_themeDetails = new DefaultConversationalTheme($conversationSettings); |
| 153 | 187 | $file_upload_tag = null; |
| 154 | 188 | $restrictionMsg = ''; |
| @@ -178,9 +212,9 @@ | ||
| 178 | 212 | } |
| 179 | 213 | } |
| 180 | 214 | $conversationNavigationHtml = $conversationalHelper->getNavigationView(); |
| 181 | 215 | |
| 182 | - $confMsg = $this->_form->getSuccessMessageMarkups(); | |
| 216 | + // $confMsg = $this->_form->getSuccessMessageMarkups(); | |
| 183 | 217 | $abandonmentMsg = $this->_form->getFormAbandonmentMessage(); |
| 184 | 218 | |
| 185 | 219 | // if (!empty($this->_buttons)) { |
| 186 | 220 | // $this->_buttons->name = $formIdentifier; |
| @@ -188,35 +222,37 @@ | ||
| 188 | 222 | // $subBtn = $this->_themeDetails->getField($this->_buttons, $buttonClass, ''); |
| 189 | 223 | // } |
| 190 | 224 | |
| 191 | 225 | if (!empty($msg)) { |
| 192 | - $restrictionMsg = <<<MSG | |
| 193 | - <div class="{$this->_form->getAtomicCls("_frm-ovrly-b{$formID}")}"> | |
| 194 | - <p class="{$this->_form->getAtomicCls("_frm-ovrly-msg-b{$formID}")}"> | |
| 195 | - $msg | |
| 226 | + $restrictionMsg = | |
| 227 | + ' | |
| 228 | + <div class="' . $this->_form->getAtomicCls("_frm-ovrly-b{$formID}") . '"> | |
| 229 | + <p class="' . $this->_form->getAtomicCls("_frm-ovrly-msg-b{$formID}") . '"> | |
| 230 | + ' . $msg . ' | |
| 196 | 231 | </p> |
| 197 | 232 | </div> |
| 198 | -MSG; | |
| 233 | + '; | |
| 199 | 234 | } |
| 200 | 235 | $formHTML = |
| 201 | - <<<HTMLa | |
| 202 | - <div id="{$formIdentifier}" class="{$this->_form->getAtomicCls("_frm-bg-b{$formID}")}"> | |
| 203 | - $restrictionMsg | |
| 204 | - <form novalidate id="form-{$formIdentifier}" class="_frm-bc{$formID}" $file_upload_tag method='post'> | |
| 205 | - <input type="text" class="d-none" name="csrf" value="{$this->_tokens['csrf']}"> | |
| 206 | - <input type="text" class="d-none" name="t_identity" value="{$this->_tokens['t_identity']}"> | |
| 207 | - {$this->honeypotField()} | |
| 208 | - <input type="text" class="d-none" name="bitforms_id" value="bitforms_{$this->_form->getFormID()}"> | |
| 209 | - <div class="bc{$formID}-steps-container"> | |
| 210 | - $welcomePageHtml | |
| 211 | - $fieldHtml | |
| 236 | + ' | |
| 237 | + <div id="' . $formIdentifier . '"' . $noTranslate['attrs'] . ' class="b' . $formID . '-bit-form ' . $this->_form->getAtomicCls("_frm-bg-b{$formID}") . ' bit-form bf-form-wrapper' . $noTranslate['cls'] . '"> | |
| 238 | + ' . $restrictionMsg . ' | |
| 239 | + <form novalidate id="form-' . $formIdentifier . '" class="_frm-bc' . $formID . ' bf-form" ' . $file_upload_tag . ' method=\'post\'> | |
| 240 | + <input type="text" class="d-none" name="csrf" value="' . $this->_tokens['csrf'] . '"> | |
| 241 | + <input type="text" class="d-none" name="t_identity" value="' . $this->_tokens['t_identity'] . '"> | |
| 242 | + ' . $this->honeypotField() . ' | |
| 243 | + <input type="text" class="d-none" name="bitforms_id" value="bitforms_' . $this->_form->getFormID() . '"> | |
| 244 | + ' . $this->languageField() . ' | |
| 245 | + <div class="bc' . $formID . '-steps-container"> | |
| 246 | + ' . $welcomePageHtml . ' | |
| 247 | + ' . $fieldHtml . ' | |
| 248 | + ' . $conversationNavigationHtml . ' | |
| 212 | 249 | </div> |
| 213 | 250 | </form> |
| 214 | - <div id='bc-form-msg-wrp-{$formIdentifier}' class="bc-form-msg-wrp"></div> | |
| 215 | - $abandonmentMsg | |
| 216 | - $conversationNavigationHtml | |
| 251 | + <div id=\'bc-form-msg-wrp-' . $formIdentifier . '\' class="bc-form-msg-wrp"></div> | |
| 252 | + ' . $abandonmentMsg . ' | |
| 217 | 253 | </div> |
| 218 | -HTMLa; | |
| 254 | +'; | |
| 219 | 255 | |
| 220 | 256 | return $formHTML; |
| 221 | 257 | } |
| 222 | 258 | |
| @@ -221,8 +257,9 @@ | ||
| 221 | 257 | } |
| 222 | 258 | |
| 223 | 259 | private function setView($hasFile, $msg) |
| 224 | 260 | { |
| 261 | + $noTranslate = $this->noTranslateMarkup(); | |
| 225 | 262 | $file_upload_tag = null; |
| 226 | 263 | $restrictionMsg = ''; |
| 227 | 264 | $formID = $this->_form->getFormID(); |
| 228 | 265 | if ($hasFile) { |
| @@ -242,32 +279,43 @@ | ||
| 242 | 279 | $fieldHtml .= $this->getLayoutHtml($layouts); |
| 243 | 280 | } else { |
| 244 | 281 | $formViewHelper = new FormViewHelper($this->_form, $this->_formContents); |
| 245 | 282 | |
| 246 | - $fieldHtml .= <<<STEPWRPR | |
| 247 | - <div class='{$this->_form->getAtomicCls("_frm-b{$formID}-stp-cntnr")}'> | |
| 248 | - {$formViewHelper->getStepHeaderHtml()} | |
| 249 | - <div class='{$this->_form->getAtomicCls("_frm-b{$formID}-stp-wrpr")}'> | |
| 250 | - {$formViewHelper->getProgressBarMarkup()} | |
| 251 | - <div class='{$this->_form->getAtomicCls("_frm-b{$formID}-stp-cntnt-wrpr")}'> | |
| 252 | -STEPWRPR; | |
| 283 | + $fieldHtml .= | |
| 284 | + ' | |
| 285 | + <div class=\'' . $this->_form->getAtomicCls("_frm-b{$formID}-stp-cntnr") . ' _frm-b-stp-cntnr\'> | |
| 286 | + ' . $formViewHelper->getStepHeaderHtml() . ' | |
| 287 | + <div class=\'' . $this->_form->getAtomicCls("_frm-b{$formID}-stp-wrpr") . ' _frm-b-stp-wrpr\'> | |
| 288 | + ' . $formViewHelper->getProgressBarMarkup() . ' | |
| 289 | + <div class=\'' . $this->_form->getAtomicCls("_frm-b{$formID}-stp-cntnt-wrpr") . ' _frm-b-stp-cntnt-wrpr\'> | |
| 290 | +'; | |
| 253 | 291 | foreach ($layouts as $key => $lay) { |
| 254 | 292 | $hideOtherSteps = $key > 0 ? 'deactive' : ''; |
| 255 | 293 | $step = $key + 1; |
| 256 | - $fieldHtml .= <<<HTMLa | |
| 257 | - <div class="{$this->_form->getAtomicCls("_frm-b{$formID}-stp-cntnt")} $hideOtherSteps" data-step="{$step}"> | |
| 258 | - <div class="_frm-b{$formID}"> | |
| 259 | - {$this->getLayoutHtml($lay->layout)} | |
| 294 | + $ariaHidden = $key > 0 ? 'aria-hidden="true"' : ''; | |
| 295 | + $fieldHtml .= | |
| 296 | + ' | |
| 297 | + <div | |
| 298 | + class="' . $this->_form->getAtomicCls("_frm-b{$formID}-stp-cntnt") . ' _frm-b-stp-cntnt ' . $hideOtherSteps . '" | |
| 299 | + data-step="' . $step . '" | |
| 300 | + role="tabpanel" | |
| 301 | + id="step-' . $formID . '-' . $step . '-panel" | |
| 302 | + aria-labelledby="step-' . $formID . '-' . $step . '-tab" | |
| 303 | + ' . $ariaHidden . ' | |
| 304 | + > | |
| 305 | + <div class="_frm-b' . $formID . ' _frm-b"> | |
| 306 | + ' . $this->getLayoutHtml($lay->layout) . ' | |
| 260 | 307 | </div> |
| 261 | - {$formViewHelper->getStepButtonMarkup()} | |
| 308 | + ' . $formViewHelper->getStepButtonMarkup() . ' | |
| 262 | 309 | </div> |
| 263 | -HTMLa; | |
| 310 | +'; | |
| 264 | 311 | } |
| 265 | - $fieldHtml .= <<<CLOSINGTAG | |
| 312 | + $fieldHtml .= | |
| 313 | + ' | |
| 266 | 314 | </div> |
| 267 | 315 | </div> |
| 268 | 316 | </div> |
| 269 | -CLOSINGTAG; | |
| 317 | +'; | |
| 270 | 318 | } |
| 271 | 319 | |
| 272 | 320 | $confMsg = $this->_form->getSuccessMessageMarkups(); |
| 273 | 321 | $abandonmentMsg = $this->_form->getFormAbandonmentMessage(); |
| @@ -278,31 +326,43 @@ | ||
| 278 | 326 | $subBtn = $this->_themeDetails->getField($this->_buttons, $buttonClass, ''); |
| 279 | 327 | } |
| 280 | 328 | |
| 281 | 329 | if (!empty($msg)) { |
| 282 | - $restrictionMsg = <<<MSG | |
| 283 | - <div class="{$this->_form->getAtomicCls("_frm-ovrly-b{$formID}")}"> | |
| 284 | - <p class="{$this->_form->getAtomicCls("_frm-ovrly-msg-b{$formID}")}"> | |
| 285 | - $msg | |
| 330 | + $restrictionMsg = | |
| 331 | + ' | |
| 332 | + <div class="' . $this->_form->getAtomicCls("_frm-ovrly-b{$formID}") . '"> | |
| 333 | + <p class="' . $this->_form->getAtomicCls("_frm-ovrly-msg-b{$formID}") . '"> | |
| 334 | + ' . $msg . ' | |
| 286 | 335 | </p> |
| 287 | 336 | </div> |
| 288 | -MSG; | |
| 337 | +'; | |
| 289 | 338 | } |
| 290 | 339 | $formHTML = |
| 291 | - <<<HTMLa | |
| 292 | - <div id="{$formIdentifier}" class="{$this->_form->getAtomicCls("_frm-bg-b{$formID}")}"> | |
| 293 | - $restrictionMsg | |
| 294 | - <form novalidate id="form-{$formIdentifier}" class="{$this->_form->getAtomicCls("_frm-b{$formID}")}" $file_upload_tag method='post'> | |
| 295 | - <input type="text" class="d-none" name="csrf" value="{$this->_tokens['csrf']}"> | |
| 296 | - <input type="text" class="d-none" name="t_identity" value="{$this->_tokens['t_identity']}"> | |
| 297 | - {$this->honeypotField()} | |
| 298 | - <input type="text" class="d-none" name="bitforms_id" value="bitforms_{$this->_form->getFormID()}"> | |
| 299 | - $fieldHtml | |
| 340 | + ' | |
| 341 | + <div id="' . $formIdentifier . '"' . $noTranslate['attrs'] . ' class="b' . $formID . '-bit-form ' . $this->_form->getAtomicCls("_frm-bg-b{$formID}") . ' bit-form bf-form-wrapper' . $noTranslate['cls'] . '"> | |
| 342 | + ' . $restrictionMsg . ' | |
| 343 | + <form novalidate id="form-' . $formIdentifier . '" class="' . $this->_form->getAtomicCls("_frm-b{$formID}") . ' bf-form" ' . $file_upload_tag . ' method=\'post\'> | |
| 344 | + <input type="text" class="d-none" name="csrf" value="' . $this->_tokens['csrf'] . '"> | |
| 345 | + <input type="text" class="d-none" name="t_identity" value="' . $this->_tokens['t_identity'] . '"> | |
| 346 | + ' . $this->honeypotField() . ' | |
| 347 | + <input type="text" class="d-none" name="bitforms_id" value="bitforms_' . $this->_form->getFormID() . '"> | |
| 348 | + ' . $this->languageField() . ' | |
| 349 | + ' . $fieldHtml . ' | |
| 300 | 350 | </form> |
| 301 | - $abandonmentMsg | |
| 302 | - <div id='bf-form-msg-wrp-{$formIdentifier}'></div> | |
| 303 | - $confMsg | |
| 351 | + ' . $abandonmentMsg . ' | |
| 352 | + <div id=\'bf-form-msg-wrp-' . $formIdentifier . '\'></div> | |
| 353 | + <!-- | |
| 354 | + Live Region for Screen Reader Announcements (Accessibility) | |
| 355 | + --> | |
| 356 | + <div | |
| 357 | + class="bf-live-region" | |
| 358 | + role="status" | |
| 359 | + aria-live="polite" | |
| 360 | + aria-atomic="true" | |
| 361 | + style="position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;" | |
| 362 | + ></div> | |
| 363 | + ' . $confMsg . ' | |
| 304 | 364 | </div> |
| 305 | -HTMLa; | |
| 365 | +'; | |
| 306 | 366 | return $formHTML; |
| 307 | 367 | } |
| 308 | 368 | } |