| @@ -7,16 +7,10 @@ | ||
| 7 | 7 | * @since 3.0 |
| 8 | 8 | */ |
| 9 | 9 | class FrmFieldFormHtml { |
| 10 | 10 | |
| 11 | - /** | |
| 12 | - * @var string | |
| 13 | - */ | |
| 14 | 11 | private $html; |
| 15 | 12 | |
| 16 | - /** | |
| 17 | - * @var string | |
| 18 | - */ | |
| 19 | 13 | private $html_id; |
| 20 | 14 | |
| 21 | 15 | /** |
| 22 | 16 | * @var FrmFieldType |
| @@ -22,21 +16,12 @@ | ||
| 22 | 16 | * @var FrmFieldType |
| 23 | 17 | */ |
| 24 | 18 | private $field_obj; |
| 25 | 19 | |
| 26 | - /** | |
| 27 | - * @var int|string | |
| 28 | - */ | |
| 29 | 20 | private $field_id; |
| 30 | 21 | |
| 31 | - /** | |
| 32 | - * @var array|object | |
| 33 | - */ | |
| 34 | 22 | private $form = array(); |
| 35 | 23 | |
| 36 | - /** | |
| 37 | - * @var array | |
| 38 | - */ | |
| 39 | 24 | private $pass_args = array(); |
| 40 | 25 | |
| 41 | 26 | /** |
| 42 | 27 | * @since 3.0 |
| @@ -56,10 +41,8 @@ | ||
| 56 | 41 | * @since 3.0 |
| 57 | 42 | * |
| 58 | 43 | * @param string $param |
| 59 | 44 | * @param array $atts |
| 60 | - * | |
| 61 | - * @return void | |
| 62 | 45 | */ |
| 63 | 46 | private function _set( $param, $atts ) { |
| 64 | 47 | if ( isset( $atts[ $param ] ) ) { |
| 65 | 48 | $this->{$param} = $atts[ $param ]; |
| @@ -69,10 +52,8 @@ | ||
| 69 | 52 | /** |
| 70 | 53 | * @since 3.0 |
| 71 | 54 | * |
| 72 | 55 | * @param array $atts |
| 73 | - * | |
| 74 | - * @return void | |
| 75 | 56 | */ |
| 76 | 57 | private function set_html( $atts ) { |
| 77 | 58 | $this->set_from_field( |
| 78 | 59 | $atts, |
| @@ -86,10 +67,8 @@ | ||
| 86 | 67 | /** |
| 87 | 68 | * @since 3.0 |
| 88 | 69 | * |
| 89 | 70 | * @param array $atts |
| 90 | - * | |
| 91 | - * @return void | |
| 92 | 71 | */ |
| 93 | 72 | private function set_field_id( $atts ) { |
| 94 | 73 | $this->set_from_field( |
| 95 | 74 | $atts, |
| @@ -103,16 +82,13 @@ | ||
| 103 | 82 | /** |
| 104 | 83 | * @since 3.0 |
| 105 | 84 | * |
| 106 | 85 | * @param array $atts |
| 107 | - * | |
| 108 | - * @return void | |
| 109 | 86 | */ |
| 110 | 87 | private function set_pass_args( $atts ) { |
| 111 | 88 | $this->pass_args = $atts; |
| 112 | 89 | |
| 113 | 90 | $exclude = array( 'field_obj', 'html' ); |
| 114 | - | |
| 115 | 91 | foreach ( $exclude as $ex ) { |
| 116 | 92 | if ( isset( $atts[ $ex ] ) ) { |
| 117 | 93 | unset( $this->pass_args[ $ex ] ); |
| 118 | 94 | } |
| @@ -123,10 +99,8 @@ | ||
| 123 | 99 | * @since 3.0 |
| 124 | 100 | * |
| 125 | 101 | * @param array $atts |
| 126 | 102 | * @param array $set |
| 127 | - * | |
| 128 | - * @return void | |
| 129 | 103 | */ |
| 130 | 104 | private function set_from_field( $atts, $set ) { |
| 131 | 105 | if ( isset( $atts[ $set['param'] ] ) ) { |
| 132 | 106 | $this->{$set['param']} = $atts[ $set['param'] ]; |
| @@ -134,11 +108,8 @@ | ||
| 134 | 108 | $this->{$set['param']} = $this->field_obj->get_field_column( $set['default'] ); |
| 135 | 109 | } |
| 136 | 110 | } |
| 137 | 111 | |
| 138 | - /** | |
| 139 | - * @return string | |
| 140 | - */ | |
| 141 | 112 | public function get_html() { |
| 142 | 113 | $this->replace_shortcodes_before_input(); |
| 143 | 114 | $this->replace_shortcodes_with_atts(); |
| 144 | 115 | $this->replace_shortcodes_after_input(); |
| @@ -147,10 +118,8 @@ | ||
| 147 | 118 | } |
| 148 | 119 | |
| 149 | 120 | /** |
| 150 | 121 | * @since 3.0 |
| 151 | - * | |
| 152 | - * @return void | |
| 153 | 122 | */ |
| 154 | 123 | private function replace_shortcodes_before_input() { |
| 155 | 124 | $this->html = apply_filters( 'frm_before_replace_shortcodes', $this->html, $this->field_obj->get_field(), $this->pass_args['errors'], $this->form ); |
| 156 | 125 | |
| @@ -172,16 +141,14 @@ | ||
| 172 | 141 | } |
| 173 | 142 | |
| 174 | 143 | /** |
| 175 | 144 | * @since 3.0 |
| 176 | - * | |
| 177 | - * @return void | |
| 178 | 145 | */ |
| 179 | 146 | private function replace_field_values() { |
| 180 | 147 | // Replace [id]. |
| 181 | 148 | $this->html = str_replace( '[id]', $this->field_id, $this->html ); |
| 182 | 149 | |
| 183 | - // Set the label for | |
| 150 | + // set the label for | |
| 184 | 151 | $this->html = str_replace( 'field_[key]', $this->html_id, $this->html ); |
| 185 | 152 | |
| 186 | 153 | // Replace [key]. |
| 187 | 154 | $this->html = str_replace( '[key]', $this->field_obj->get_field_column( 'field_key' ), $this->html ); |
| @@ -191,10 +158,8 @@ | ||
| 191 | 158 | } |
| 192 | 159 | |
| 193 | 160 | /** |
| 194 | 161 | * @since 3.0 |
| 195 | - * | |
| 196 | - * @return void | |
| 197 | 162 | */ |
| 198 | 163 | private function replace_required_label_shortcode() { |
| 199 | 164 | $required = FrmField::is_required( $this->field_obj->get_field() ) ? $this->field_obj->get_field_column( 'required_indicator' ) : ''; |
| 200 | 165 | FrmShortcodeHelper::remove_inline_conditions( ! empty( $required ), 'required_label', $required, $this->html ); |
| @@ -204,17 +169,12 @@ | ||
| 204 | 169 | * If this is an HTML field, the values are included in the description. |
| 205 | 170 | * In this case, we don't want to run the wp shortcodes with the description included. |
| 206 | 171 | * |
| 207 | 172 | * @since 3.0 |
| 208 | - * | |
| 209 | - * @param bool $wp_processed | |
| 210 | - * | |
| 211 | - * @return void | |
| 212 | 173 | */ |
| 213 | 174 | private function maybe_replace_description_shortcode( $wp_processed = false ) { |
| 214 | 175 | $is_html = 'html' === $this->field_obj->get_field_column( 'type' ); |
| 215 | - $should_replace = $is_html ? $wp_processed : ! $wp_processed; | |
| 216 | - | |
| 176 | + $should_replace = ( $is_html && $wp_processed ) || ( ! $is_html && ! $wp_processed ); | |
| 217 | 177 | if ( $should_replace ) { |
| 218 | 178 | $this->replace_description_shortcode(); |
| 219 | 179 | } |
| 220 | 180 | } |
| @@ -220,16 +180,13 @@ | ||
| 220 | 180 | } |
| 221 | 181 | |
| 222 | 182 | /** |
| 223 | 183 | * @since 3.0 |
| 224 | - * | |
| 225 | - * @return void | |
| 226 | 184 | */ |
| 227 | 185 | private function replace_description_shortcode() { |
| 228 | 186 | $this->maybe_add_description_id(); |
| 229 | 187 | $description = FrmAppHelper::maybe_kses( $this->field_obj->get_field_column( 'description' ) ); |
| 230 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 231 | - FrmShortcodeHelper::remove_inline_conditions( $description && $description != '', 'description', $description, $this->html ); | |
| 188 | + FrmShortcodeHelper::remove_inline_conditions( ( $description && $description != '' ), 'description', $description, $this->html ); | |
| 232 | 189 | } |
| 233 | 190 | |
| 234 | 191 | /** |
| 235 | 192 | * Add an ID to the description for aria-describedby. |
| @@ -235,15 +192,11 @@ | ||
| 235 | 192 | * Add an ID to the description for aria-describedby. |
| 236 | 193 | * This ID was added to the HTML in v3.0. |
| 237 | 194 | * |
| 238 | 195 | * @since 3.0 |
| 239 | - * | |
| 240 | - * @return void | |
| 241 | 196 | */ |
| 242 | 197 | private function maybe_add_description_id() { |
| 243 | 198 | $description = $this->field_obj->get_field_column( 'description' ); |
| 244 | - | |
| 245 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 246 | 199 | if ( $description != '' ) { |
| 247 | 200 | $this->add_element_id( 'description', 'desc' ); |
| 248 | 201 | } |
| 249 | 202 | } |
| @@ -251,17 +204,11 @@ | ||
| 251 | 204 | /** |
| 252 | 205 | * Insert an ID if it doesn't exist. |
| 253 | 206 | * |
| 254 | 207 | * @since 3.06.02 |
| 255 | - * | |
| 256 | - * @param string $param | |
| 257 | - * @param string $id | |
| 258 | - * | |
| 259 | - * @return void | |
| 260 | 208 | */ |
| 261 | 209 | private function add_element_id( $param, $id ) { |
| 262 | 210 | preg_match_all( '/(\[if\s+' . $param . '\])(.*?)(\[\/if\s+' . $param . '\])/mis', $this->html, $inner_html ); |
| 263 | - | |
| 264 | 211 | if ( ! isset( $inner_html[2] ) ) { |
| 265 | 212 | return; |
| 266 | 213 | } |
| 267 | 214 | |
| @@ -268,51 +215,33 @@ | ||
| 268 | 215 | if ( ! is_string( $inner_html[2] ) && count( $inner_html[2] ) === 1 ) { |
| 269 | 216 | $inner_html[2] = $inner_html[2][0]; |
| 270 | 217 | } |
| 271 | 218 | |
| 272 | - if ( ! is_string( $inner_html[2] ) ) { | |
| 273 | - return; | |
| 219 | + if ( is_string( $inner_html[2] ) ) { | |
| 220 | + $has_id = strpos( $inner_html[2], ' id=' ); | |
| 221 | + if ( ! $has_id ) { | |
| 222 | + $id = 'frm_' . $id . '_' . $this->html_id; | |
| 223 | + $this->html = str_replace( 'class="frm_' . $param, 'id="' . esc_attr( $id ) . '" class="frm_' . esc_attr( $param ), $this->html ); | |
| 224 | + } | |
| 274 | 225 | } |
| 275 | - | |
| 276 | - $has_id = str_contains( $inner_html[2], ' id=' ); | |
| 277 | - | |
| 278 | - if ( $has_id ) { | |
| 279 | - return; | |
| 280 | - } | |
| 281 | - | |
| 282 | - $id = 'frm_' . $id . '_' . $this->html_id; | |
| 283 | - $this->html = str_replace( 'class="frm_' . $param, 'id="' . esc_attr( $id ) . '" class="frm_' . esc_attr( $param ), $this->html ); | |
| 284 | 226 | } |
| 285 | 227 | |
| 286 | 228 | /** |
| 287 | 229 | * @since 3.0 |
| 288 | - * | |
| 289 | - * @return void | |
| 290 | 230 | */ |
| 291 | 231 | private function replace_error_shortcode() { |
| 292 | 232 | $this->maybe_add_error_id(); |
| 293 | - $error = $this->pass_args['errors'][ 'field' . $this->field_id ] ?? false; | |
| 233 | + $error = isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ? $this->pass_args['errors'][ 'field' . $this->field_id ] : false; | |
| 294 | 234 | |
| 295 | - if ( ! $error ) { | |
| 296 | - FrmShortcodeHelper::remove_inline_conditions( false, 'error', $error, $this->html ); | |
| 297 | - return; | |
| 298 | - } | |
| 299 | - | |
| 300 | - $include_alert_role_on_field_errors = FrmAppHelper::should_include_alert_role_on_field_errors(); | |
| 301 | - $has_alert_role = str_contains( $this->html, 'role="alert"' ); | |
| 302 | - | |
| 303 | - if ( ! $has_alert_role && $include_alert_role_on_field_errors ) { | |
| 235 | + if ( ! empty( $error ) && false === strpos( $this->html, 'role="alert"' ) && FrmAppHelper::should_include_alert_role_on_field_errors() ) { | |
| 304 | 236 | $error_body = self::get_error_body( $this->html ); |
| 305 | - | |
| 306 | - if ( is_string( $error_body ) && ! str_contains( $error_body, 'role=' ) ) { | |
| 237 | + if ( is_string( $error_body ) && false === strpos( $error_body, 'role=' ) ) { | |
| 307 | 238 | $new_error_body = preg_replace( '/class="frm_error/', 'role="alert" class="frm_error', $error_body, 1 ); |
| 308 | 239 | $this->html = str_replace( '[if error]' . $error_body . '[/if error]', '[if error]' . $new_error_body . '[/if error]', $this->html ); |
| 309 | 240 | } |
| 310 | - } elseif ( ! $include_alert_role_on_field_errors && $has_alert_role ) { | |
| 311 | - $this->html = str_replace( 'role="alert"', '', $this->html ); | |
| 312 | 241 | } |
| 313 | 242 | |
| 314 | - FrmShortcodeHelper::remove_inline_conditions( true, 'error', $error, $this->html ); | |
| 243 | + FrmShortcodeHelper::remove_inline_conditions( ! empty( $error ), 'error', $error, $this->html ); | |
| 315 | 244 | } |
| 316 | 245 | |
| 317 | 246 | /** |
| 318 | 247 | * Pull the HTML between [if error] and [/if error] shortcodes. |
| @@ -317,25 +246,23 @@ | ||
| 317 | 246 | /** |
| 318 | 247 | * Pull the HTML between [if error] and [/if error] shortcodes. |
| 319 | 248 | * |
| 320 | 249 | * @param string $html |
| 321 | - * | |
| 322 | - * @return false|string | |
| 250 | + * @return string|false | |
| 323 | 251 | */ |
| 324 | 252 | private static function get_error_body( $html ) { |
| 325 | 253 | $start = strpos( $html, '[if error]' ); |
| 326 | - | |
| 327 | 254 | if ( false === $start ) { |
| 328 | 255 | return false; |
| 329 | 256 | } |
| 330 | 257 | |
| 331 | 258 | $end = strpos( $html, '[/if error]', $start ); |
| 332 | - | |
| 333 | 259 | if ( false === $end ) { |
| 334 | 260 | return false; |
| 335 | 261 | } |
| 336 | 262 | |
| 337 | - return substr( $html, $start + 10, $end - $start - 10 ); | |
| 263 | + $error_body = substr( $html, $start + 10, $end - $start - 10 ); | |
| 264 | + return $error_body; | |
| 338 | 265 | } |
| 339 | 266 | |
| 340 | 267 | /** |
| 341 | 268 | * Add an ID to the error message for aria-describedby. |
| @@ -341,10 +268,8 @@ | ||
| 341 | 268 | * Add an ID to the error message for aria-describedby. |
| 342 | 269 | * This ID was added to the HTML in v3.06.02. |
| 343 | 270 | * |
| 344 | 271 | * @since 3.06.02 |
| 345 | - * | |
| 346 | - * @return void | |
| 347 | 272 | */ |
| 348 | 273 | private function maybe_add_error_id() { |
| 349 | 274 | if ( ! isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ) { |
| 350 | 275 | return; |
| @@ -356,10 +281,8 @@ | ||
| 356 | 281 | /** |
| 357 | 282 | * Replace [required_class] |
| 358 | 283 | * |
| 359 | 284 | * @since 3.0 |
| 360 | - * | |
| 361 | - * @return void | |
| 362 | 285 | */ |
| 363 | 286 | private function replace_required_class() { |
| 364 | 287 | $required_class = FrmField::is_required( $this->field_obj->get_field() ) ? ' frm_required_field' : ''; |
| 365 | 288 | $this->html = str_replace( '[required_class]', $required_class, $this->html ); |
| @@ -366,35 +289,29 @@ | ||
| 366 | 289 | } |
| 367 | 290 | |
| 368 | 291 | /** |
| 369 | 292 | * @since 3.0 |
| 370 | - * | |
| 371 | - * @return void | |
| 372 | 293 | */ |
| 373 | 294 | private function replace_form_shortcodes() { |
| 374 | - if ( ! $this->form ) { | |
| 375 | - return; | |
| 376 | - } | |
| 295 | + if ( ! empty( $this->form ) ) { | |
| 296 | + $form = (array) $this->form; | |
| 377 | 297 | |
| 378 | - $form = (array) $this->form; | |
| 298 | + // Replace [form_key]. | |
| 299 | + $this->html = str_replace( '[form_key]', $form['form_key'], $this->html ); | |
| 379 | 300 | |
| 380 | - // Replace [form_key]. | |
| 381 | - $this->html = str_replace( '[form_key]', $form['form_key'], $this->html ); | |
| 382 | - | |
| 383 | - // Replace [form_name]. | |
| 384 | - $this->html = str_replace( '[form_name]', $form['name'], $this->html ); | |
| 301 | + // Replace [form_name]. | |
| 302 | + $this->html = str_replace( '[form_name]', $form['name'], $this->html ); | |
| 303 | + } | |
| 385 | 304 | } |
| 386 | 305 | |
| 387 | 306 | /** |
| 388 | 307 | * @since 3.0 |
| 389 | - * | |
| 390 | - * @return void | |
| 391 | 308 | */ |
| 392 | 309 | public function replace_shortcodes_after_input() { |
| 393 | 310 | $this->html .= "\n"; |
| 394 | 311 | |
| 395 | 312 | // Stop html filtering on confirmation field to prevent loop |
| 396 | - if ( $this->field_obj->get_field_column( 'conf_field' ) !== 'stop' ) { | |
| 313 | + if ( $this->field_obj->get_field_column( 'conf_field' ) != 'stop' ) { | |
| 397 | 314 | $this->filter_for_more_shortcodes(); |
| 398 | 315 | } |
| 399 | 316 | } |
| 400 | 317 | |
| @@ -399,10 +316,8 @@ | ||
| 399 | 316 | } |
| 400 | 317 | |
| 401 | 318 | /** |
| 402 | 319 | * @since 3.0 |
| 403 | - * | |
| 404 | - * @return void | |
| 405 | 320 | */ |
| 406 | 321 | private function filter_for_more_shortcodes() { |
| 407 | 322 | $atts = $this->pass_args; |
| 408 | 323 | |
| @@ -421,13 +336,11 @@ | ||
| 421 | 336 | * |
| 422 | 337 | * @since 3.0 |
| 423 | 338 | * |
| 424 | 339 | * @param string $html |
| 425 | - * | |
| 426 | - * @return void | |
| 427 | 340 | */ |
| 428 | 341 | public function remove_collapse_shortcode( &$html ) { |
| 429 | - if ( str_contains( $html, '[collapse_this]' ) ) { | |
| 342 | + if ( strpos( $html, '[collapse_this]' ) ) { | |
| 430 | 343 | $html = str_replace( '[collapse_this]', '', $html ); |
| 431 | 344 | } |
| 432 | 345 | } |
| 433 | 346 | |
| @@ -432,10 +345,8 @@ | ||
| 432 | 345 | } |
| 433 | 346 | |
| 434 | 347 | /** |
| 435 | 348 | * @since 3.0 |
| 436 | - * | |
| 437 | - * @return void | |
| 438 | 349 | */ |
| 439 | 350 | private function replace_shortcodes_with_atts() { |
| 440 | 351 | preg_match_all( "/\[(input|deletelink)\b(.*?)(?:(\/))?\]/s", $this->html, $shortcodes, PREG_PATTERN_ORDER ); |
| 441 | 352 | |
| @@ -441,13 +352,14 @@ | ||
| 441 | 352 | |
| 442 | 353 | foreach ( $shortcodes[0] as $short_key => $tag ) { |
| 443 | 354 | $shortcode_atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][ $short_key ] ); |
| 444 | 355 | $tag = FrmShortcodeHelper::get_shortcode_tag( $shortcodes, $short_key ); |
| 445 | - $replace_with = ''; | |
| 446 | 356 | |
| 447 | - if ( $tag === 'deletelink' && FrmAppHelper::pro_is_installed() ) { | |
| 357 | + $replace_with = ''; | |
| 358 | + | |
| 359 | + if ( $tag == 'deletelink' && FrmAppHelper::pro_is_installed() ) { | |
| 448 | 360 | $replace_with = FrmProEntriesController::entry_delete_link( $shortcode_atts ); |
| 449 | - } elseif ( $tag === 'input' ) { | |
| 361 | + } elseif ( $tag == 'input' ) { | |
| 450 | 362 | $replace_with = $this->replace_input_shortcode( $shortcode_atts ); |
| 451 | 363 | } |
| 452 | 364 | |
| 453 | 365 | $this->html = str_replace( $shortcodes[0][ $short_key ], $replace_with, $this->html ); |
| @@ -460,8 +372,9 @@ | ||
| 460 | 372 | * @return string |
| 461 | 373 | */ |
| 462 | 374 | private function replace_input_shortcode( $shortcode_atts ) { |
| 463 | 375 | $shortcode_atts = $this->prepare_input_shortcode_atts( $shortcode_atts ); |
| 376 | + | |
| 464 | 377 | return $this->field_obj->include_front_field_input( $this->pass_args, $shortcode_atts ); |
| 465 | 378 | } |
| 466 | 379 | |
| 467 | 380 | /** |
| @@ -470,12 +383,12 @@ | ||
| 470 | 383 | * @return array |
| 471 | 384 | */ |
| 472 | 385 | private function prepare_input_shortcode_atts( $shortcode_atts ) { |
| 473 | 386 | if ( isset( $shortcode_atts['opt'] ) ) { |
| 474 | - --$shortcode_atts['opt']; | |
| 387 | + $shortcode_atts['opt'] --; | |
| 475 | 388 | } |
| 476 | 389 | |
| 477 | - $field_class = $shortcode_atts['class'] ?? ''; | |
| 390 | + $field_class = isset( $shortcode_atts['class'] ) ? $shortcode_atts['class'] : ''; | |
| 478 | 391 | $this->field_obj->set_field_column( 'input_class', $field_class ); |
| 479 | 392 | |
| 480 | 393 | if ( isset( $shortcode_atts['class'] ) ) { |
| 481 | 394 | unset( $shortcode_atts['class'] ); |
| @@ -480,9 +393,9 @@ | ||
| 480 | 393 | if ( isset( $shortcode_atts['class'] ) ) { |
| 481 | 394 | unset( $shortcode_atts['class'] ); |
| 482 | 395 | } |
| 483 | 396 | |
| 484 | - $this->field_obj->set_aria_invalid_error( $shortcode_atts, $this->pass_args ); | |
| 397 | + $shortcode_atts['aria-invalid'] = isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ? 'true' : 'false'; | |
| 485 | 398 | |
| 486 | 399 | $this->field_obj->set_field_column( 'shortcodes', $shortcode_atts ); |
| 487 | 400 | |
| 488 | 401 | return $shortcode_atts; |
| @@ -492,10 +405,8 @@ | ||
| 492 | 405 | * Add the label position class into the HTML |
| 493 | 406 | * If the label position is inside, add a class to show the label if the field has a value. |
| 494 | 407 | * |
| 495 | 408 | * @since 3.0 |
| 496 | - * | |
| 497 | - * @return void | |
| 498 | 409 | */ |
| 499 | 410 | private function add_class_to_label() { |
| 500 | 411 | $label_class = $this->field_obj->get_label_class(); |
| 501 | 412 | $this->html = str_replace( '[label_position]', $label_class, $this->html ); |
| @@ -504,10 +415,8 @@ | ||
| 504 | 415 | /** |
| 505 | 416 | * Replace [entry_key] |
| 506 | 417 | * |
| 507 | 418 | * @since 3.0 |
| 508 | - * | |
| 509 | - * @return void | |
| 510 | 419 | */ |
| 511 | 420 | private function replace_entry_key() { |
| 512 | 421 | $entry_key = FrmAppHelper::simple_get( 'entry', 'sanitize_title' ); |
| 513 | 422 | $this->html = str_replace( '[entry_key]', $entry_key, $this->html ); |
| @@ -516,21 +425,17 @@ | ||
| 516 | 425 | /** |
| 517 | 426 | * Add classes to a field div |
| 518 | 427 | * |
| 519 | 428 | * @since 3.0 |
| 520 | - * | |
| 521 | - * @return void | |
| 522 | 429 | */ |
| 523 | 430 | private function add_field_div_classes() { |
| 524 | 431 | $classes = $this->get_field_div_classes(); |
| 525 | 432 | |
| 526 | - if ( in_array( $this->field_obj->get_field_column( 'type' ), array( 'html', 'summary' ), true ) && ! str_contains( $this->html, '[error_class]' ) ) { | |
| 527 | - // There is no error_class shortcode for HTML fields | |
| 528 | - $this->html = str_replace( 'class="frm_form_field', 'class="frm_form_field ' . esc_attr( $classes ), $this->html ); | |
| 529 | - return; | |
| 433 | + if ( $this->field_obj->get_field_column( 'type' ) == 'html' && strpos( $this->html, '[error_class]' ) === false ) { | |
| 434 | + // there is no error_class shortcode for HTML fields | |
| 435 | + $this->html = str_replace( 'class="frm_form_field', 'class="frm_form_field ' . $classes, $this->html ); | |
| 530 | 436 | } |
| 531 | - | |
| 532 | - $this->html = str_replace( '[error_class]', esc_attr( $classes ), $this->html ); | |
| 437 | + $this->html = str_replace( '[error_class]', $classes, $this->html ); | |
| 533 | 438 | } |
| 534 | 439 | |
| 535 | 440 | /** |
| 536 | 441 | * Get the classes for a field div |
| @@ -536,9 +441,9 @@ | ||
| 536 | 441 | * Get the classes for a field div |
| 537 | 442 | * |
| 538 | 443 | * @since 3.0 |
| 539 | 444 | * |
| 540 | - * @return string Classes. | |
| 445 | + * @return string $classes | |
| 541 | 446 | */ |
| 542 | 447 | private function get_field_div_classes() { |
| 543 | 448 | // Add error class |
| 544 | 449 | $classes = isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ? ' frm_blank_field' : ''; |
| @@ -544,12 +449,11 @@ | ||
| 544 | 449 | $classes = isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ? ' frm_blank_field' : ''; |
| 545 | 450 | |
| 546 | 451 | // Add label position class |
| 547 | 452 | $settings = $this->field_obj->display_field_settings(); |
| 548 | - | |
| 549 | - if ( ! empty( $settings['label_position'] ) ) { | |
| 453 | + if ( isset( $settings['label_position'] ) && $settings['label_position'] ) { | |
| 550 | 454 | $label_position = $this->field_obj->get_field_column( 'label' ); |
| 551 | - $classes .= ' frm_' . $label_position . '_container'; | |
| 455 | + $classes .= ' frm_' . $label_position . '_container'; | |
| 552 | 456 | |
| 553 | 457 | // Add class if field has value, to be used for floating label styling. |
| 554 | 458 | if ( 'inside' === $label_position && $this->field_obj->get_field_column( 'value' ) ) { |
| 555 | 459 | $classes .= ' frm_label_float_top'; |
| @@ -557,14 +461,12 @@ | ||
| 557 | 461 | } |
| 558 | 462 | |
| 559 | 463 | // Add CSS layout classes |
| 560 | 464 | $extra_classes = $this->field_obj->get_field_column( 'classes' ); |
| 561 | - | |
| 562 | - if ( $extra_classes ) { | |
| 563 | - if ( ! str_contains( $this->html, 'frm_form_field ' ) ) { | |
| 465 | + if ( ! empty( $extra_classes ) ) { | |
| 466 | + if ( ! strpos( $this->html, 'frm_form_field ' ) ) { | |
| 564 | 467 | $classes .= ' frm_form_field'; |
| 565 | 468 | } |
| 566 | - | |
| 567 | 469 | $classes .= ' ' . $extra_classes; |
| 568 | 470 | } |
| 569 | 471 | |
| 570 | 472 | $classes .= $this->field_obj->get_container_class(); |
| @@ -569,12 +471,9 @@ | ||
| 569 | 471 | |
| 570 | 472 | $classes .= $this->field_obj->get_container_class(); |
| 571 | 473 | |
| 572 | 474 | // Get additional classes |
| 573 | - $classes = apply_filters( 'frm_field_div_classes', $classes, $this->field_obj->get_field(), array( 'field_id' => $this->field_id ) ); | |
| 574 | - | |
| 575 | - // Remove unexpected characters from class. | |
| 576 | - return implode( ' ', array_map( 'FrmFormsHelper::sanitize_layout_class', explode( ' ', $classes ) ) ); | |
| 475 | + return apply_filters( 'frm_field_div_classes', $classes, $this->field_obj->get_field(), array( 'field_id' => $this->field_id ) ); | |
| 577 | 476 | } |
| 578 | 477 | |
| 579 | 478 | /** |
| 580 | 479 | * This filters shortcodes in the field HTML |
| @@ -579,10 +478,8 @@ | ||
| 579 | 478 | /** |
| 580 | 479 | * This filters shortcodes in the field HTML |
| 581 | 480 | * |
| 582 | 481 | * @since 3.0 |
| 583 | - * | |
| 584 | - * @return void | |
| 585 | 482 | */ |
| 586 | 483 | private function process_wp_shortcodes() { |
| 587 | 484 | if ( apply_filters( 'frm_do_html_shortcodes', true ) ) { |
| 588 | 485 | $this->html = do_shortcode( $this->html ); |
| @@ -592,9 +489,8 @@ | ||
| 592 | 489 | /** |
| 593 | 490 | * Adds multiple input attributes. |
| 594 | 491 | * |
| 595 | 492 | * @since 6.4.1 |
| 596 | - * | |
| 597 | 493 | * @return void |
| 598 | 494 | */ |
| 599 | 495 | private function add_multiple_input_attributes() { |
| 600 | 496 | $field_type = $this->field_obj->get_field_column( 'type' ); |
| @@ -620,13 +516,8 @@ | ||
| 620 | 516 | |
| 621 | 517 | // Add 'aria-required' attribute to the field if required. |
| 622 | 518 | if ( $is_radio && '1' === $field['required'] ) { |
| 623 | 519 | $attributes['aria-required'] = 'true'; |
| 624 | - } | |
| 625 | - | |
| 626 | - // Add 'aria-invalid' attribute to the group if there are errors. | |
| 627 | - if ( isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ) { | |
| 628 | - $attributes['aria-invalid'] = 'true'; | |
| 629 | 520 | } |
| 630 | 521 | |
| 631 | 522 | // Concatenate attributes into a string, and replace the role="group" in the HTML with the attributes string. |
| 632 | 523 | $html_attributes = FrmAppHelper::array_to_html_params( $attributes ); |