render_form(absint($attributes["id"] ?? 0)), ); wp_register_script( "noesis-forms-block", plugins_url("assets/block.min.js", FILE), [ "wp-blocks", "wp-element", "wp-block-editor", "wp-components", "wp-api-fetch", "wp-server-side-render", ], asset_stamp("block.min.js"), true, ); wp_add_inline_script( "noesis-forms-block", "window.NF_BLOCK=" . wp_json_encode( [ "logoURL" => wp_make_link_relative( plugins_url("assets/feather-forms.svg", FILE), ), ], JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT, ) . ";", "before", ); register_block_type("noesis-forms/form", [ "api_version" => 3, "title" => "Feather Forms", "category" => "widgets", "icon" => "feedback", "attributes" => ["formId" => ["type" => "integer", "default" => 0]], "editor_script" => "noesis-forms-block", "render_callback" => static fn($attributes) => render_form( (int) ($attributes["formId"] ?? 0), ), ]); } function contact_embed(): string { $copy = function_exists("noesis_content") ? \noesis_content("contact") : []; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only view selection; changes and private data use separate capability and nonce checks. $interest = sanitize_key(wp_unslash($_GET["interest"] ?? "")); $product = $copy["productEnquiries"][$interest] ?? []; $prefill = []; if ($product) { $prefill = [ "service" => $product["service"] ?? "", "message" => $product["message"] ?? "", ]; } $context = $product ? '

' . esc_html($product["heading"] ?? "") . "

" . esc_html($product["text"] ?? "") . "

" : ""; return '
' . $context . render_form((int) get_option("noesis_forms_contact_id"), $prefill) . "
"; } function render_form( int $id, array $prefill = [], bool $preview = false, ): string { $form = get_form($id); if (!$form || (!$preview && !form_open($form))) { return $form && $form["status"] === "active" ? '

' . esc_html($form["settings"]["closed_message"]) . "

" : ""; } if (!defined("DONOTCACHEPAGE")) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound -- Standard WordPress cache integration constant, not a plugin-defined API. define("DONOTCACHEPAGE", true); } if (!headers_sent()) { nocache_headers(); } $framework = $form["settings"]["framework"] ?? "native"; wp_enqueue_style( $framework === "native" ? "noesis-forms-native" : "noesis-forms-base", plugins_url( $framework === "native" ? "assets/forms.min.css" : "assets/forms-base.min.css", FILE, ), [], asset_stamp( $framework === "native" ? "forms.min.css" : "forms-base.min.css", ), ); wp_enqueue_script( "noesis-forms", plugins_url("assets/forms.min.js", FILE), [], asset_stamp("forms.min.js"), ["strategy" => "defer", "in_footer" => true], ); $instance = wp_unique_id("nf-" . $id . "-"); $s = $form["settings"]; $captcha = captcha_config(); $config = [ "restNonce" => is_user_logged_in() ? wp_create_nonce("wp_rest") : "", "preview" => $preview, "frameworkClasses" => framework_classes($framework), "conversions" => array_filter( $s, static fn($key) => str_starts_with($key, "conversion_"), ARRAY_FILTER_USE_KEY, ), "id" => $id, "schema" => $form["schema"], "settings" => array_intersect_key( $s, array_flip([ "submit_label", "next_label", "back_label", "show_progress", ]), ), "endpoint" => wp_make_link_relative( rest_url("noesis-forms/v1/submit/" . $id), ), "tokenEndpoint" => wp_make_link_relative( rest_url("noesis-forms/v1/token/" . $id), ), "captcha" => [ "required" => !$preview && $captcha["required"], "siteKey" => $captcha["site_key"], ], ]; ob_start(); ?>
;--nf-hover:" data-nf-wrap>
" data-nf-form method="post" enctype="multipart/form-data" action=""> ">"> 1 && $s["show_progress"] ): ?> $page): ?>
"> > ' . esc_html($page["description"]) . "

"; } ?>

Protected by reCAPTCHA. Google’s Privacy Policy and Terms of Service apply.

'; } $content = ""; if ($type === "heading") { $content = "

" . $label . "

"; } elseif ($type === "paragraph") { $content = "

" . nl2br(esc_html($f["help"] ?: $f["label"])) . "

"; } elseif ($type === "divider") { $content = "
"; } else { $mark = $f["required"] ? ' ' : ' (optional)'; $group = in_array( $type, ["radio", "checkboxes", "rating", "repeater"], true, ); if ($group) { $content .= '
' . $label . $mark . ""; } elseif (!in_array($type, ["checkbox", "consent"], true)) { $content .= '"; } $attrs = ' id="' . esc_attr($id) . '" name="' . esc_attr($name) . '" aria-describedby="' . esc_attr($described) . '"' . $required; if ($f["autocomplete"]) { $attrs .= ' autocomplete="' . esc_attr($f["autocomplete"]) . '"'; } if ($f["placeholder"]) { $attrs .= ' placeholder="' . esc_attr($f["placeholder"]) . '"'; } if ($type === "textarea") { $content .= "' . esc_textarea($value) . ""; } elseif (in_array($type, ["select", "multiselect"], true)) { if ($type === "multiselect") { $attrs = str_replace( 'name="' . esc_attr($name) . '"', 'name="' . esc_attr($name) . '[]" multiple size="4"', $attrs, ); } $content .= ($framework === "bulma" ? '
' : ($framework === "elementor" ? '
' : "")) . "" . ($type === "select" ? '' : ""); foreach ($f["options"] as $option) { $content .= '"; } $content .= "" . (in_array($framework, ["bulma", "elementor"], true) ? "
" : ""); } elseif ($group && $type !== "repeater") { $options = $type === "rating" ? array_map( static fn($i) => [ "label" => (string) $i, "value" => (string) $i, ], range(1, 5), ) : $f["options"]; $content .= '
'; foreach ($options as $i => $option) { $content .= '"; } $content .= "
"; } elseif (in_array($type, ["checkbox", "consent"], true)) { $content .= '"; } elseif ($type === "file") { $content .= ' "." . $ext, $f["extensions"], ), ), ) . '"' . ($f["max_files"] > 1 ? " multiple" : "") . $required . ' aria-describedby="' . esc_attr($described) . '">' . esc_html( strtoupper(implode(", ", $f["extensions"])) . " · Up to " . $f["max_mb"] . " MB per file · " . $f["max_files"] . " file" . ($f["max_files"] === 1 ? "" : "s"), ) . ""; } elseif ($type === "repeater") { $content .= '
'; } else { if ($type === "calculation") { $attrs .= " readonly"; } if (in_array($type, ["number", "range"], true)) { if ($f["min"] !== null) { $attrs .= ' min="' . esc_attr($f["min"]) . '"'; } if ($f["max"] !== null) { $attrs .= ' max="' . esc_attr($f["max"]) . '"'; } $attrs .= ' step="' . esc_attr($f["step"]) . '"'; } $content .= '"; if ($type === "range") { $content .= ''; } } $content .= '' . esc_html($f["help"]) . ''; } return '
' . $content . "
"; }