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, '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' ] ); } } /** * 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() {} /** * 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->post_title ); ?>

form->post_excerpt, wpforms_builder_preview_get_allowed_tags() ); ?>
no_fields_options(); ?> no_fields_preview(); ?>
form ); ?>

 

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 ) ); ?> form_data ); ?>
[ 'group_name' => esc_html__( 'Standard Fields', 'wpforms-lite' ), 'fields' => [], ], 'fancy' => [ 'group_name' => esc_html__( 'Fancy Fields', 'wpforms-lite' ), 'fields' => [], ], 'payment' => [ 'group_name' => esc_html__( 'Payment Fields', 'wpforms-lite' ), 'fields' => [], ], ]; $fields = apply_filters( 'wpforms_builder_fields_buttons', $fields ); // Output the buttons. foreach ( $fields as $id => $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['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; } $fields = $this->form_data['fields']; foreach ( $fields as $field ) { $css = ! empty( $field['size'] ) ? 'size-' . esc_attr( $field['size'] ) : ''; $css .= ! empty( $field['label_hide'] ) ? ' label_hide' : ''; $css .= ! empty( $field['sublabel_hide'] ) ? ' sublabel_hide' : ''; $css .= ! empty( $field['required'] ) ? ' required' : ''; $css .= ! empty( $field['input_columns'] ) && $field['input_columns'] === '2' ? ' wpforms-list-2-columns' : ''; $css .= ! empty( $field['input_columns'] ) && $field['input_columns'] === '3' ? ' wpforms-list-3-columns' : ''; $css .= ! empty( $field['input_columns'] ) && $field['input_columns'] === 'inline' ? ' wpforms-list-inline' : ''; $css .= isset( $field['meta']['delete'] ) && $field['meta']['delete'] === false ? ' no-delete' : ''; $css = apply_filters( 'wpforms_field_preview_class', $css, $field ); if ( ! has_action( "wpforms_display_field_{$field['type']}" ) ) { $this->unavailable_fields_preview( $field ); continue; } printf( '
', esc_attr( $field['type'] ), esc_attr( $css ), esc_attr( $field['id'] ) ); if ( apply_filters( 'wpforms_field_preview_display_duplicate_button', true, $field, $this->form_data ) ) { printf( '', esc_html__( 'Duplicate Field', 'wpforms-lite' ) ); } printf( '', esc_html__( 'Delete Field', 'wpforms-lite' ) ); printf( // language=HTML PhpStorm. '
%s %s
', esc_html__( 'Click to edit.', 'wpforms-lite' ), esc_html__( 'Drag to reorder.', 'wpforms-lite' ) ); do_action( "wpforms_builder_fields_previews_{$field['type']}", $field ); 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 . '' ); echo '
'; 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' ), esc_attr( $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() { // phpcs:disable WordPress.WP.I18n // Checkbox, Radio, and Payment Multiple/Checkbox field choices. ?>