Form preview · Responses are not sent from this page.
' . // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- render_form escapes dynamic values by context; this authenticated preview requires the complete form HTML. $html . ""Feather Forms (default)", "theme" => "Theme styles / minimal", "uikit" => "YOOtheme / UIkit 3", "bootstrap" => "Bootstrap 5", "tailwind" => "Tailwind CSS", "elementor" => "Elementor", "divi" => "Divi", "bulma" => "Bulma", "foundation" => "Foundation 6", ]); } function framework_classes(string $framework): array { $maps = [ "bootstrap" => [ "grid" => "row g-4", "half" => "col-12 col-md-6", "full" => "col-12", "input" => "form-control", "select" => "form-select", "check" => "form-check-input", "label" => "form-label", "help" => "form-text", "error" => "text-danger", "button" => "btn btn-dark", "back" => "btn btn-outline-secondary", "success" => "alert alert-success", "errors" => "alert alert-danger", ], "uikit" => [ "form" => "uk-form-stacked", "grid" => "uk-grid uk-grid-small", "half" => "uk-width-1-1 uk-width-1-2@s", "full" => "uk-width-1-1", "input" => "uk-input", "textarea" => "uk-textarea", "select" => "uk-select", "check" => "uk-checkbox", "radio" => "uk-radio", "label" => "uk-form-label", "help" => "uk-text-meta", "error" => "uk-text-danger", "button" => "uk-button uk-button-secondary", "back" => "uk-button uk-button-default", "success" => "uk-alert-success", "errors" => "uk-alert-danger", ], "tailwind" => [ "grid" => "grid grid-cols-1 md:grid-cols-2 gap-6", "half" => "col-span-1", "full" => "col-span-1 md:col-span-2", "input" => "block w-full rounded-lg border border-gray-400 bg-white px-4 py-3 text-base text-gray-800 focus:outline-2 focus:outline-offset-2 focus:outline-sky-700", "check" => "h-5 w-5 accent-gray-700", "label" => "block mb-2 font-medium text-base", "help" => "block mt-2 text-sm text-gray-600", "error" => "block mt-2 text-sm text-red-700", "button" => "inline-flex items-center justify-center rounded-lg bg-gray-700 px-6 py-3 text-base font-semibold text-white hover:bg-red-700 focus:outline-2 focus:outline-offset-2 focus:outline-sky-700", "back" => "rounded-lg border border-gray-300 px-6 py-3 text-base font-medium", "success" => "rounded-xl border border-emerald-200 bg-emerald-50 p-6", "errors" => "rounded-lg border border-red-300 bg-red-50 p-4 text-red-800", ], "elementor" => [ "grid" => "elementor-form-fields-wrapper elementor-labels-above", "half" => "elementor-field-group elementor-column elementor-col-50 elementor-sm-100", "full" => "elementor-field-group elementor-column elementor-col-100", "input" => "elementor-field elementor-size-sm elementor-field-textual", "check" => "elementor-field", "label" => "elementor-field-label", "button" => "elementor-button elementor-size-sm", "back" => "elementor-button elementor-size-sm", "errors" => "elementor-message elementor-message-danger", "success" => "elementor-message elementor-message-success", ], "divi" => [ "wrapper" => "et_pb_contact", "half" => "et_pb_contact_field et_pb_contact_field_half", "full" => "et_pb_contact_field", "input" => "input", "check" => "input", "button" => "et_pb_button", "back" => "et_pb_button", "success" => "et-pb-contact-message", "errors" => "et-pb-contact-message", ], "bulma" => [ "grid" => "columns is-multiline", "half" => "column is-half", "full" => "column is-full", "input" => "input", "textarea" => "textarea", "check" => "checkbox", "label" => "label", "help" => "help", "error" => "help is-danger", "button" => "button is-dark", "back" => "button is-light", "success" => "notification is-success is-light", "errors" => "notification is-danger is-light", ], "foundation" => [ "grid" => "grid-x grid-margin-x", "half" => "cell small-12 medium-6", "full" => "cell small-12", "input" => "", "label" => "", "help" => "help-text", "error" => "form-error is-visible", "button" => "button", "back" => "button secondary", "success" => "callout success", "errors" => "callout alert", ], ]; return apply_filters( "noesis_forms_framework_classes", $maps[$framework] ?? [], $framework, ); } function add_classes(\WP_HTML_Tag_Processor $tags, string $classes): void { foreach (explode(" ", $classes) as $class) { if ($class !== "") { $tags->add_class($class); } } } function adapt_markup(string $html, string $framework): string { if ($framework === "native") { return $html; } $map = framework_classes($framework); $tags = new \WP_HTML_Tag_Processor($html); while ($tags->next_tag()) { $tag = $tags->get_tag(); $type = $tags->get_attribute("type"); $classes = explode(" ", (string) $tags->get_attribute("class")); $key = ""; if (in_array("nf-wrap", $classes, true)) { $key = "wrapper"; } elseif (in_array("nf-form", $classes, true)) { $key = "form"; } elseif (in_array("nf-grid", $classes, true)) { $key = "grid"; } elseif (in_array("nf-field", $classes, true)) { $key = in_array("nf-width-half", $classes, true) ? "half" : "full"; } elseif (in_array("nf-button", $classes, true)) { $key = "button"; } elseif ( in_array("nf-back", $classes, true) || in_array("nf-add-row", $classes, true) || in_array("nf-remove-row", $classes, true) ) { $key = "back"; } elseif ( in_array("nf-help", $classes, true) || in_array("nf-file-hint", $classes, true) ) { $key = "help"; } elseif (in_array("nf-field-error", $classes, true)) { $key = "error"; } elseif (in_array("nf-errors", $classes, true)) { $key = "errors"; } elseif (in_array("nf-success", $classes, true)) { $key = "success"; } elseif ($tag === "LABEL" && !in_array("nf-choice", $classes, true)) { $key = "label"; } elseif ($tag === "INPUT" && $type !== "hidden") { $key = in_array($type, ["checkbox", "radio"], true) ? ($type === "radio" && isset($map["radio"]) ? "radio" : "check") : "input"; } elseif ($tag === "TEXTAREA") { $key = isset($map["textarea"]) ? "textarea" : "input"; } elseif ($tag === "SELECT") { $key = isset($map["select"]) ? "select" : ($framework === "bulma" ? "" : "input"); } if ($key && isset($map[$key])) { add_classes($tags, $map[$key]); } } return apply_filters( "noesis_forms_framework_markup", $tags->get_updated_html(), $framework, ); } function preview_page(): void { if (!isset($_GET["noesis_form_preview"])) { return; } $id = absint($_GET["noesis_form_preview"]); if ( !allowed() || !wp_verify_nonce( sanitize_text_field(wp_unslash($_GET["_wpnonce"] ?? "")), "nf_preview_" . $id, ) ) { status_header(403); exit("You cannot preview this form."); } $form = get_form($id); if (!$form) { status_header(404); exit(); } $html = render_form($id, [], true); nocache_headers(); header("X-Robots-Tag: noindex, nofollow"); echo '
Form preview · Responses are not sent from this page.
' . // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- render_form escapes dynamic values by context; this authenticated preview requires the complete form HTML. $html . "