true ) ); } wp_enqueue_script( 'stackmime-forms' ); } /** * Load the form styles, unless the site owner chose to style forms in the theme. */ function stackmime_forms_enqueue_style() { $s = stackmime_forms_settings(); if ( 'none' === $s['style'] ) { return; } wp_enqueue_style( 'stackmime-forms', STACKMIME_FORMS_URL . 'assets/css/forms.css', array(), STACKMIME_FORMS_VERSION ); $accent = sanitize_hex_color( (string) $s['accent'] ); if ( $accent ) { wp_add_inline_style( 'stackmime-forms', '.sm-form{--smf-accent:' . $accent . '}' ); } } add_action( 'wp_footer', function () { if ( ! wp_script_is( 'stackmime-forms', 'enqueued' ) ) { return; } $config = array( 'rest' => esc_url_raw( rest_url( 'stackmime-forms/v1/' ) ), 'forms' => array_keys( $GLOBALS['stackmime_forms_on_page'] ), 'minSeconds' => (int) stackmime_forms_settings()['min_seconds'], 'failText' => stackmime_forms_fail_message(), 'i18n' => array( 'required' => __( 'This is required.', 'stackmime-forms' ), 'missing' => __( 'Please fill in the highlighted fields.', 'stackmime-forms' ), 'sending' => __( 'Sending…', 'stackmime-forms' ), 'email' => __( 'Please enter a valid email address.', 'stackmime-forms' ), ), ); wp_add_inline_script( 'stackmime-forms', 'window.StackMimeFormsConfig = ' . wp_json_encode( $config ) . ';', 'before' ); }, 1 ); add_shortcode( 'stackmime_form', function ( $atts ) { $atts = shortcode_atts( array( 'id' => 'contact', 'class' => '', ), $atts, 'stackmime_form' ); return stackmime_forms_render( $atts['id'], array( 'class' => $atts['class'] ) ); } ); /** * Markup for one form. * * @param string $id Form ID. * @param array $args class: extra CSS classes. * @return string HTML. */ function stackmime_forms_render( $id, $args = array() ) { $id = sanitize_key( $id ); $form = stackmime_forms_get( $id ); if ( ! $form ) { /* translators: %s: form ID. */ return current_user_can( 'edit_posts' ) ? '

StackMime Forms: ' . esc_html( sprintf( __( 'there is no form with the ID "%s".', 'stackmime-forms' ), $id ) ) . '

' : ''; } stackmime_forms_enqueue( $id ); stackmime_forms_enqueue_style(); static $n = 0; ++$n; $uid = 'smf-' . $id . '-' . $n; $classes = array( 'sm-form', 'sm-form--' . $id ); foreach ( preg_split( '/\s+/', (string) ( $args['class'] ?? '' ) ) as $c ) { if ( '' !== $c ) { $classes[] = sanitize_html_class( $c ); } } /** * Extra data-* attributes on the form element, e.g. for an add-on's script. * * @param array $attrs data-name => value. * @param string $id Form ID. * @param array $form Form definition. */ $form_attrs = stackmime_forms_data_attributes( apply_filters( 'stackmime_forms_form_attributes', array(), $id, $form ) ); ob_start(); ?>
novalidate> $field ) : ?> value. * @param string $key Field key. * @param array $field Field definition. * @param array $form Form definition. */ $attrs = stackmime_forms_data_attributes( apply_filters( 'stackmime_forms_field_attributes', array( 'data-sm-key' => $key ), $key, $field, $form ) ); ?>
>

>

>
> *' : ''; ?> $label ) : ?>
'name', 'email' => 'email', 'phone' => 'tel', 'company' => 'organization', ); $extra = isset( $auto[ $key ] ) ? ' autocomplete="' . esc_attr( $auto[ $key ] ) . '"' : ''; if ( 'email' === $type && ! isset( $auto[ $key ] ) ) { $extra = ' autocomplete="email"'; } elseif ( 'tel' === $type && ! isset( $auto[ $key ] ) ) { $extra = ' autocomplete="tel"'; } elseif ( 'url' === $type ) { $extra = ' autocomplete="url" inputmode="url"'; } ?> placeholder="">

value (scalars; arrays are JSON-encoded). * @return string Attributes with a leading space each. */ function stackmime_forms_data_attributes( $attrs ) { $out = ''; foreach ( (array) $attrs as $name => $value ) { if ( ! is_string( $name ) || ! preg_match( '/^data-[a-z0-9-]{1,40}$/', $name ) ) { continue; } $value = is_array( $value ) ? wp_json_encode( $value ) : (string) $value; $out .= ' ' . $name . '="' . esc_attr( $value ) . '"'; } return $out; }