tag (since * Pro 2.4). We only mark the page here; markup echoed here would land * outside the form and never be posted. * - filter `elementor_pro/forms/render/item` ( array $item, int $item_index, Form $form ) * applied for every field while the
body is being rendered. * We echo our hidden fields once per form on the first item; this is * the only extension point inside the form body, so we use it instead * of the `render_form_before` hook named in the spec, which does not * exist in Pro 3.x. The widget renders into an output buffer, so the * echo lands in the right place. Also marks the page (belt and braces). * - action `elementor_pro/forms/validation` ( Form_Record $record, Ajax_Handler $ajax_handler ) * runs after field validation and before any submit action (mail, * webhook, etc). Any error registered here stops the actions. * queue -> add_error_message( held message ) * block -> add_error_message( block message ) * Elementor Pro has no "spam" entry status; refusing the submission * is its own honeypot's behaviour too. * * Elementor posts the form with FormData to admin-ajax.php, so our hidden * fields arrive as top-level $_POST keys and the usual Router helpers apply. * * @package AgentLane */ namespace AgentLane\Adapters; use AgentLane\Router; if ( ! defined( 'ABSPATH' ) ) { exit; } require_once __DIR__ . '/interface-adapter.php'; /** * Class AdapterElementor */ class AdapterElementor implements AdapterInterface { /** * Field types with no user text. * * @var string[] */ const SKIP_TYPES = array( 'honeypot', 'recaptcha', 'recaptcha_v3', 'hcaptcha', 'upload', 'password', 'step', 'html', ); /** * Object hash of the form widget we last injected fields into. * * @var string */ private static $last_form = ''; /** * {@inheritDoc} */ public function id(): string { return 'elementor'; } /** * {@inheritDoc} */ public function register(): void { if ( ! self::is_available() ) { // Elementor Pro defines its classes on plugins_loaded; retry at init. if ( ! did_action( 'init' ) ) { add_action( 'init', array( $this, 'register' ), 1 ); } return; } add_action( 'elementor_pro/forms/pre_render', array( $this, 'mark_page' ), 10, 2 ); add_filter( 'elementor_pro/forms/render/item', array( $this, 'inject_fields' ), 10, 3 ); add_action( 'elementor_pro/forms/validation', array( $this, 'validate' ), 5, 2 ); } /** * Elementor Pro present? * * @return bool */ public static function is_available(): bool { return class_exists( 'ElementorPro\Plugin' ); } /** * Mark the page on render. * * @param mixed $instance Widget settings. * @param mixed $form Form widget. * @return void */ public function mark_page( $instance = null, $form = null ) { Router::mark_page_has_form(); } /** * Echo hidden fields once per form widget, on its first field. * * @param mixed $item Field settings. * @param mixed $item_index Field index. * @param mixed $form Form widget. * @return mixed */ public function inject_fields( $item, $item_index = 0, $form = null ) { Router::mark_page_has_form(); $hash = is_object( $form ) ? spl_object_hash( $form ) : 'none'; $first = ( 0 === (int) $item_index ) || ( $hash !== self::$last_form ); if ( $first ) { self::$last_form = $hash; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- markup is escaped inside Signals::render_hidden_fields(). echo Router::hidden_fields(); } return $item; } /** * Score and, if needed, refuse the submission. * * @param mixed $record Form_Record (not type-hinted on purpose). * @param mixed $ajax_handler Ajax_Handler. * @return void */ public function validate( $record, $ajax_handler = null ) { if ( ! is_object( $record ) || ! method_exists( $record, 'get' ) || ! is_object( $ajax_handler ) ) { return; } $form_id = ''; if ( method_exists( $record, 'get_form_settings' ) ) { $name = (string) $record->get_form_settings( 'form_name' ); $wid = (string) $record->get_form_settings( 'id' ); $form_id = '' !== trim( $name ) ? trim( $name ) : $wid; } if ( '' === $form_id ) { $form_id = Router::post_value( 'form_id' ); } $fields = $this->extract_fields( $record ); $verdict = Router::handle( 'elementor', $form_id, $fields ); if ( null === $verdict || 'allow' === $verdict->action ) { return; } $message = ( 'block' === $verdict->action ) ? Router::block_message() : Router::held_message(); // Both calls are needed. As far as the Elementor Pro source is known to us, the form // counts as failed only when the handler's field error list is not empty, and that // list is filled by add_error(); add_error_message() only sets the text shown to the // visitor. With the message alone the visitor would read "held" while the email // still went out (security review 2026-11-18, item 2). The key 'agentlane' matches no // form field, so no field is highlighted. Not run against a live Elementor Pro. if ( method_exists( $ajax_handler, 'add_error' ) ) { $ajax_handler->add_error( 'agentlane', $message ); } if ( method_exists( $ajax_handler, 'add_error_message' ) ) { $ajax_handler->add_error_message( $message ); } } /** * Record fields to title => value. Keys are field ids when no title. * * @param object $record Form_Record. * @return array */ private function extract_fields( $record ): array { $fields = $record->get( 'fields' ); if ( ! is_array( $fields ) ) { return array(); } $out = array(); foreach ( $fields as $id => $field ) { if ( ! is_array( $field ) ) { continue; } $type = (string) ( $field['type'] ?? '' ); if ( in_array( $type, self::SKIP_TYPES, true ) ) { continue; } $title = trim( (string) ( $field['title'] ?? '' ) ); $name = '' !== $title ? $title : (string) $id; if ( isset( $out[ $name ] ) ) { $name .= ' (' . $id . ')'; } $out[ $name ] = $field['value'] ?? ( $field['raw_value'] ?? '' ); } return $out; } }