name = esc_html__( 'Fields', 'wpforms-lite' ); $this->slug = 'fields'; $this->icon = 'fa-list-alt'; $this->order = 10; $this->sidebar = true; if ( $this->form ) { add_action( 'wpforms_builder_fields', [ $this, 'search' ], 5 ); add_action( 'wpforms_builder_fields', [ $this, 'fields' ] ); add_action( 'wpforms_builder_fields_options', [ $this, 'fields_options' ] ); add_action( 'wpforms_builder_preview', [ $this, 'preview' ] ); // Template for form builder previews. add_action( 'wpforms_builder_print_footer_scripts', [ $this, 'field_preview_templates' ] ); add_action( 'wpforms_builder_print_footer_scripts', [ $this, 'choices_limit_message_template' ] ); add_action( 'wpforms_builder_print_footer_scripts', [ $this, 'choices_empty_message_template' ] ); } } /** * Enqueue assets for the Fields panel. * * @since 1.0.0 * @since 1.6.8 All the builder stylesheets enqueues moved to the `\WPForms_Builder::enqueues()`. */ public function enqueues() { $min = wpforms_get_min_suffix(); wp_enqueue_script( 'wpforms-builder-drag-fields', WPFORMS_PLUGIN_URL . "assets/js/components/admin/builder/drag-fields{$min}.js", [ 'wpforms-builder' ], WPFORMS_VERSION, true ); wp_enqueue_script( 'wpforms-builder-search-fields', WPFORMS_PLUGIN_URL . "assets/js/components/admin/builder/search-fields{$min}.js", [ 'wpforms-builder' ], WPFORMS_VERSION, true ); } /** * Output the Field panel sidebar. * * @since 1.0.0 */ public function panel_sidebar() { // Sidebar contents are not valid unless we have a form. if ( ! $this->form ) { return; } ?>
form ); ?>
form ); ?>
form ) { echo '
'; echo wp_kses( __( 'You need to setup your form before you can manage the fields.', 'wpforms-lite' ), [ 'a' => [ 'href' => [], 'class' => [], 'data-panel' => [], ], ] ); echo '
'; return; } ?>

form_data['settings']['form_title'] ) ? $this->form_data['settings']['form_title'] : $this->form->post_title ); ?>

form_data['settings']['form_desc'] ) ? $this->form_data['settings']['form_desc'] : $this->form->post_excerpt, wpforms_builder_preview_get_allowed_tags() ); ?>
no_fields_options(); ?> no_fields_preview(); ?>
form ); ?>

hCaptcha

reCAPTCHA

Turnstile

form_data['settings']['submit_text'] ) ? $this->form_data['settings']['submit_text'] : esc_html__( 'Submit', 'wpforms-lite' ); $submit_style = empty( $this->form_data['fields'] ) ? 'display: none;' : ''; printf( '

', esc_attr( $submit_style ), esc_attr( $submit ) ); /** This action is documented in includes/class-frontend.php. */ do_action( 'wpforms_display_submit_after', $this->form_data, 'submit' ); // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName ?> form_data ); ?>
$group ) { usort( $group['fields'], [ $this, 'field_order' ] ); echo '
'; echo ''; echo '' . esc_html( $group['group_name'] ) . ''; echo ''; echo ''; echo '
'; foreach ( $group['fields'] as $field ) { /** * Attributes of the form field button on the Add Fields tab in the Form Builder. * * @since 1.5.1 * * @param array $attributes Field attributes. * @param array $field Field data. * @param array $form_data Form data. */ $atts = apply_filters( 'wpforms_builder_field_button_attributes', [ 'id' => 'wpforms-add-fields-' . $field['type'], 'class' => [ 'wpforms-add-fields-button' ], 'data' => [ 'field-type' => $field['type'], ], 'atts' => [], ], $field, $this->form_data ); if ( ! empty( $field['keywords'] ) ) { $atts['data']['field-keywords'] = $field['keywords']; } if ( ! empty( $field['class'] ) ) { $atts['class'][] = $field['class']; } echo ''; } echo '
'; echo '
'; } } /** * Editor Field Options. * * @since 1.0.0 */ public function fields_options() { // Check to make sure the form actually has fields created already. if ( empty( $this->form_data['fields'] ) ) { $this->no_fields_options(); return; } $fields = $this->form_data['fields']; foreach ( $fields as $field ) { $class = apply_filters( 'wpforms_builder_field_option_class', '', $field ); printf( '
', sanitize_html_class( $field['type'] ), wpforms_sanitize_classes( $class ), (int) $field['id'], (int) $field['id'] ); printf( '', (int) $field['id'], (int) $field['id'] ); printf( '', (int) $field['id'], esc_attr( $field['type'] ) ); do_action( "wpforms_builder_fields_options_{$field['type']}", $field ); echo '
'; } } /** * Editor preview (right pane). * * @since 1.0.0 */ public function preview() { // Check to make sure the form actually has fields created already. if ( empty( $this->form_data['fields'] ) ) { $this->no_fields_preview(); return; } /** * Filters the fields which must be displayed on the base level on the preview panel in the Form Builder. * * @since 1.7.7 * * @param array $fields Form fields data. */ $fields = (array) apply_filters( 'wpforms_builder_panel_fields_preview_fields', $this->form_data['fields'] ); foreach ( $fields as $field ) { $this->preview_single_field( $field, [] ); } } /** * Preview single field. * * @since 1.7.7 * * @param array $field Field data. * @param array $args Additional arguments. */ public function preview_single_field( $field, $args ) { $class = ! empty( $field['size'] ) ? 'size-' . esc_attr( $field['size'] ) : ''; $class .= ! empty( $field['label_hide'] ) ? ' label_hide' : ''; $class .= isset( $field['label'] ) && empty( $field['label'] ) && $field['type'] !== 'html' ? ' label_empty' : ''; $class .= ! empty( $field['sublabel_hide'] ) ? ' sublabel_hide' : ''; $class .= ! empty( $field['required'] ) ? ' required' : ''; $class .= isset( $field['meta']['delete'] ) && $field['meta']['delete'] === false ? ' no-delete' : ''; $class .= isset( $field['meta']['duplicate'] ) && $field['meta']['duplicate'] === false ? ' no-duplicate' : ''; if ( ! empty( $field['input_columns'] ) ) { $class .= $field['input_columns'] === '2' ? ' wpforms-list-2-columns' : ''; $class .= $field['input_columns'] === '3' ? ' wpforms-list-3-columns' : ''; $class .= $field['input_columns'] === 'inline' ? ' wpforms-list-inline' : ''; } /** * Filters class attribute of the field preview container in the Form Builder. * * @since 1.4.0 * * @param string $css Field preview class. * @param array $field Field data. */ $class = apply_filters( 'wpforms_field_preview_class', $class, $field ); // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName if ( ! has_action( "wpforms_display_field_{$field['type']}" ) ) { $this->unavailable_fields_preview( $field ); return; } printf( '
', esc_attr( $field['type'] ), esc_attr( $class ), absint( $field['id'] ) ); /** * Filters display field duplicate button flag. * * @since 1.5.6.2 * * @param bool $display_duplicate_button Display field duplicate button flag. * @param array $field Field data. * @param array $form_data Form data. */ if ( apply_filters( 'wpforms_field_preview_display_duplicate_button', true, $field, $this->form_data ) ) { // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName printf( '', esc_attr__( 'Duplicate Field', 'wpforms-lite' ) ); } printf( '', esc_attr__( 'Delete Field', 'wpforms-lite' ) ); if ( empty( $_COOKIE['wpforms_field_helper_hide'] ) ) { printf( '
%s %s
', esc_html__( 'Click to Edit', 'wpforms-lite' ), esc_html__( 'Drag to Reorder', 'wpforms-lite' ), esc_attr__( 'Hide Helper', 'wpforms-lite' ) ); } /** * Fires after the field preview output in the Form Builder. * * @since 1.0.0 * * @param array $field Field data. */ do_action( "wpforms_builder_fields_previews_{$field['type']}", $field ); // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName echo '
'; } /** * Generate HTML for hidden inputs from given data. * * @since 1.6.7 * * @param array $data Field array data. * @param string $name Input name prefix. */ private function generate_hidden_inputs( $data = [], $name = '' ) { if ( ! is_array( $data ) || empty( $data ) ) { return; } foreach ( $data as $key => $value ) { if ( $key === 'id' ) { continue; } $key = ! empty( $data['id'] ) ? sprintf( '[%s][%s]', $data['id'], $key ) : sprintf( '[%s]', $key ); if ( ! empty( $name ) ) { $key = trim( $name ) . $key; } if ( is_array( $value ) ) { $this->generate_hidden_inputs( $value, $key ); } else { printf( "", esc_attr( $key ), esc_attr( $value ) ); } } } /** * Unavailable builder field display. * * @since 1.6.7 * * @param array $field Field array data. */ public function unavailable_fields_preview( $field ) { // Using ucwords() for certain fields may generate incorrect words. switch ( $field['type'] ) { case 'url': $field_type = 'URL'; break; case 'html': $field_type = 'HTML'; break; case 'gdpr-checkbox': $field_type = 'GDPR Checkbox'; break; default: $field_type = ucwords( preg_replace( '/[_-]/', ' ', $field['type'] ) ); } $warning_message = sprintf( /* translators: %s - unavailable field name. */ esc_html__( 'Unfortunately, the %s field is not available and will be ignored on the front end.', 'wpforms-lite' ), '' . $field_type . '' ); $field_id = isset( $field['id'] ) ? $field['id'] : 0; printf( '
', absint( $field_id ) ); printf( '

%1$s

%3$s
', $warning_message, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped 'https://wpforms.com/docs/how-to-import-and-export-wpforms/#field-missing', esc_html__( 'Learn More', 'wpforms-lite' ), esc_attr__( 'Dismiss this message. The field will be deleted as well.', 'wpforms-lite' ), absint( $field_id ) ); // Save unavailable fields data in hidden inputs. $this->generate_hidden_inputs( $field, 'fields' ); echo '
'; } /** * No fields options markup. * * @since 1.6.0 */ public function no_fields_options() { printf( '

%s

', esc_html__( 'You don\'t have any fields yet.', 'wpforms-lite' ) ); } /** * No fields preview placeholder markup. * * @since 1.6.0 */ public function no_fields_preview() { printf( '

%1$s

%2$s

', esc_html__( 'You don\'t have any fields yet. Add some!', 'wpforms-lite' ), esc_html__( 'Take your pick from our wide variety of fields and start building out your form!', 'wpforms-lite' ) ); } /** * Sort Add Field buttons by order provided. * * @since 1.0.0 * * @param array $a First item. * @param array $b Second item. * * @return array */ public function field_order( $a, $b ) { return $a['order'] - $b['order']; } /** * Template for form builder preview. * * @since 1.4.5 */ public function field_preview_templates() { // Checkbox, Radio, and Payment Multiple/Checkbox field choices. ?>