PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 4.3.18
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v4.3.18
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Services / FormBuilder / Components / Name.php

Name.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 4.3.18, at app/Services/FormBuilder/Components/Name.php

96 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Services\FormBuilder\Components;
4
5 use FluentForm\App\Helpers\Helper;
6 use FluentForm\Framework\Helpers\ArrayHelper;
7 use FluentForm\App\Services\FormBuilder\Components\Select;
8
9 class Name extends Select
10 {
11 /**
12 * Compile and echo the html element
13 *
14 * @param array $data [element data]
15 * @param \stdClass $form [Form Object]
16 *
17 * @return void
18 */
19 public function compile($data, $form)
20 {
21 $elementName = $data['element'];
22
23 $data = apply_filters('fluentform_rendering_field_data_' . $elementName, $data, $form);
24
25 $rootName = $data['attributes']['name'];
26
27 $hasConditions = $this->hasConditions($data) ? 'has-conditions ' : '';
28
29 if (empty($data['attributes']['class'])) {
30 $data['attributes']['class'] = '';
31 }
32
33 $data['attributes']['class'] .= $hasConditions;
34 $data['attributes']['class'] .= ' ff-field_container ff-name-field-wrapper';
35 if ($containerClass = ArrayHelper::get($data, 'settings.container_class')) {
36 $data['attributes']['class'] .= ' ' . $containerClass;
37 }
38 $atts = $this->buildAttributes(
39 ArrayHelper::except($data['attributes'], 'name')
40 );
41
42 $html = "<div {$atts}>"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $atts is escaped before being passed in.
43 $html .= "<div class='ff-t-container'>";
44
45 $labelPlacement = ArrayHelper::get($data, 'settings.label_placement');
46 $labelPlacementClass = '';
47
48 if ($labelPlacement) {
49 $labelPlacementClass = ' ff-el-form-' . $labelPlacement;
50 }
51
52 foreach ($data['fields'] as $field) {
53 if ($field['settings']['visible']) {
54 $fieldName = $field['attributes']['name'];
55 $field['attributes']['name'] = $rootName . '[' . $fieldName . ']';
56 @$field['attributes']['class'] = trim(
57 'ff-el-form-control ' .
58 $field['attributes']['class']
59 );
60
61 if ($tabIndex = Helper::getNextTabIndex()) {
62 $field['attributes']['tabindex'] = $tabIndex;
63 }
64
65 @$field['settings']['container_class'] .= $labelPlacementClass;
66
67 $field['attributes']['id'] = $this->makeElementId($field, $form);
68 $nameTitleClass = '';
69 $atts = $this->buildAttributes($field['attributes']);
70
71 if ('select' == $field['attributes']['type']) {
72 if (! defined('FLUENTFORMPRO')) {
73 continue;
74 }
75 $nameTitleClass = ' ff-name-title';
76
77 $defaultValues = (array) $this->extractValueFromAttributes($field);
78
79 $options = $this->buildOptions($field, $defaultValues);
80
81 $elMarkup = '<select ' . $atts . '>' . $options . '</select>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $atts and $options are escaped before being passed in.
82 } else {
83 $elMarkup = '<input ' . $atts . '>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $atts is escaped before being passed in.
84 }
85
86 $inputTextMarkup = $this->buildElementMarkup($elMarkup, $field, $form);
87 $html .= "<div class='ff-t-cell " . esc_attr($nameTitleClass) . "'>{$inputTextMarkup}</div>"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $inputTextMarkup is escaped before being passed in.
88 }
89 }
90 $html .= '</div>';
91 $html .= '</div>';
92
93 $this->printContent('fluentform_rendering_field_html_' . $elementName, $html, $data, $form);
94 }
95 }
96