' . esc_html__( 'Fillaro: this form does not exist or is a draft.', 'fillaro' ) . '

' : ''; } Assets::enqueue(); ++self::$instance; $uid = 'pf-' . $form['id'] . '-' . self::$instance; $theme = $form['theme']; $state = FallbackHandler::consume_state(); if ( ! is_array( $state ) || (int) $state['form_id'] !== (int) $form['id'] ) { $state = null; } $wrap_classes = array( 'pf', 'pf-container--' . $theme['container'], 'pf-inputs--' . $theme['inputStyle'], 'pf-buttons--' . $theme['buttonStyle'], ); /** * Filters a message shown in place of the form, for example when it * is closed or full. The builder preview always shows the form. * * @param string $message Safe HTML; empty to show the form. * @param array $form Form. */ $closed = $preview ? '' : (string) apply_filters( 'fillaro/form_closed', '', $form ); $ctx_tags = array( 'form' => $form ); $errors = $state && ! $state['done'] && isset( $state['errors'] ) ? (array) $state['errors'] : array(); $old = $state && ! $state['done'] && isset( $state['old'] ) ? (array) $state['old'] : array(); ob_start(); ?>
>
element, from add-ons. * * @param array $form Form. * @return string Escaped attribute string. */ private static function form_attributes( array $form ) { /** * Filters extra attributes of the
element. * * @param array $attrs Attribute => value. * @param array $form Form. */ $attrs = (array) apply_filters( 'fillaro/form_attributes', array(), $form ); $html = ''; foreach ( $attrs as $name => $value ) { if ( is_string( $name ) && preg_match( '/^[a-z][a-z0-9\-]*$/', $name ) && is_scalar( $value ) ) { $html .= sprintf( ' %s="%s"', esc_attr( $name ), esc_attr( (string) $value ) ); } } return $html; } /** * One field with its label, help and error slot. * * @param array $field Field. * @param string $uid Unique form instance prefix. * @param array $tags Smart tag context. * @param array $old Previous values after a no-JS error. * @param array $errors Previous errors after a no-JS error. * @return string */ private static function render_field( array $field, $uid, array $tags, array $old, array $errors ) { $type = Plugin::instance()->fields->get( $field['type'] ); if ( ! $type ) { return ''; } $id = $uid . '-' . $field['key']; $help_id = '' !== $field['help'] ? $id . '-help' : ''; $err_id = $id . '-error'; $error = isset( $errors[ $field['key'] ] ) ? (string) $errors[ $field['key'] ] : ''; if ( array_key_exists( $field['key'], $old ) ) { $value = $old[ $field['key'] ]; } elseif ( '' !== $field['defaultValue'] ) { $value = SmartTags::replace( $field['defaultValue'], $tags ); } else { $value = ''; } $ctx = array( 'id' => $id, 'name' => 'fields[' . $field['key'] . ']', 'value' => $value, 'describedby' => trim( $help_id . ' ' . $err_id ), 'form_id' => (int) $tags['form']['id'], ); $control = $type->render_control( $field, $ctx ); if ( 'hidden' === $field['type'] ) { return $control; } $classes = array_filter( array( 'pf-field', 'pf-field--' . $field['type'], 'pf-w-' . $field['width'], $field['required'] ? 'is-required' : '', '' !== $error ? 'has-error' : '', $field['cssClass'], ) ); /** * Filters the attributes of a field's wrapper element. Add-ons use this * for data attributes, for example conditional logic rules. * * @param array $attrs Attribute => value. * @param array $field Field. * @param array $form Form. */ $wrap_attrs = (array) apply_filters( 'fillaro/field_wrapper_attributes', array( 'class' => implode( ' ', $classes ), 'data-pf-field' => $field['key'], 'data-pf-type' => $field['type'], ), $field, $tags['form'] ); $wrap_attr_html = ''; foreach ( $wrap_attrs as $attr => $attr_value ) { if ( false === $attr_value || null === $attr_value ) { continue; } $wrap_attr_html .= true === $attr_value ? ' ' . esc_attr( $attr ) : sprintf( ' %s="%s"', esc_attr( $attr ), esc_attr( (string) $attr_value ) ); } if ( ! $type->has_value() ) { return sprintf( '%s', $wrap_attr_html, $control ); } $label_text = '' !== $field['label'] ? $field['label'] : $type->label(); $label_cls = 'pf-label' . ( $field['hideLabel'] ? ' pf-sr' : '' ); $required = $field['required'] ? '' : ''; $group = $type->is_group( $field ); if ( 'consent' === $field['type'] ) { $label = '' !== $field['label'] && ! $field['hideLabel'] ? sprintf( '
%s%s
', esc_html( $field['label'] ), $required ) : ''; } elseif ( $group ) { $label = sprintf( '%s%s', esc_attr( $label_cls ), esc_html( $label_text ), $required ); } else { $label = sprintf( '', esc_attr( $label_cls ), esc_attr( $id ), esc_html( $label_text ), $required ); } $help = $help_id ? sprintf( '

%s

', esc_attr( $help_id ), esc_html( $field['help'] ) ) : ''; $err = sprintf( '

%s

', esc_attr( $err_id ), '' === $error ? ' hidden' : '', esc_html( $error ) ); $tag = $group ? 'fieldset' : 'div'; return sprintf( '<%1$s%2$s>%3$s%4$s%5$s%6$s', $tag, $wrap_attr_html, $label, $control, $help, $err ); } }