/* ========================================================= RECRUITMENT HERO REQUEST DEMO FORM - FINAL ========================================================= */ /* ========================================================= REGISTER REST API ENDPOINT ========================================================= */ add_action('rest_api_init', function () { register_rest_route( 'recruitment-hero/v1', '/demo', array( 'methods' => WP_REST_Server::CREATABLE, 'callback' => 'rh_request_demo_handle_submission', 'permission_callback' => '__return_true', ) ); }); /* ========================================================= HANDLE REQUEST DEMO SUBMISSION ========================================================= */ function rh_request_demo_handle_submission(WP_REST_Request $request) { /* ===================================================== GET REQUEST DATA ====================================================== */ $data = $request->get_json_params(); if (!is_array($data)) { return new WP_Error( 'rh_demo_invalid_request', 'Invalid form submission.', array( 'status' => 400, ) ); } /* ===================================================== HONEYPOT SPAM CHECK ====================================================== */ $website = isset($data['website']) ? sanitize_text_field( wp_unslash($data['website']) ) : ''; /* * If bot fills hidden field, * return fake success without sending email. */ if (!empty($website)) { return new WP_REST_Response( array( 'success' => true, 'message' => 'Thank you! Your demo request has been submitted successfully.', ), 200 ); } /* ===================================================== SANITIZE FORM DATA ====================================================== */ $first_name = isset($data['first_name']) ? sanitize_text_field( wp_unslash($data['first_name']) ) : ''; $last_name = isset($data['last_name']) ? sanitize_text_field( wp_unslash($data['last_name']) ) : ''; $email = isset($data['email']) ? sanitize_email( wp_unslash($data['email']) ) : ''; $phone = isset($data['phone']) ? sanitize_text_field( wp_unslash($data['phone']) ) : ''; $organization = isset($data['organization']) ? sanitize_text_field( wp_unslash($data['organization']) ) : ''; $role = isset($data['role']) ? sanitize_key( wp_unslash($data['role']) ) : ''; $team_size = isset($data['team_size']) ? sanitize_text_field( wp_unslash($data['team_size']) ) : ''; $message = isset($data['message']) ? sanitize_textarea_field( wp_unslash($data['message']) ) : ''; /* ===================================================== REQUIRED FIELD VALIDATION ====================================================== */ if ( empty($first_name) || empty($last_name) || empty($email) || empty($organization) || empty($role) ) { return new WP_Error( 'rh_demo_required_fields', 'Please complete all required fields.', array( 'status' => 422, ) ); } /* ===================================================== EMAIL VALIDATION ====================================================== */ if (!is_email($email)) { return new WP_Error( 'rh_demo_invalid_email', 'Please enter a valid email address.', array( 'status' => 422, ) ); } /* ===================================================== FIELD LENGTH VALIDATION ====================================================== */ if ( strlen($first_name) > 80 || strlen($last_name) > 80 || strlen($email) > 190 || strlen($phone) > 40 || strlen($organization) > 150 || strlen($message) > 3000 ) { return new WP_Error( 'rh_demo_invalid_length', 'One or more fields contain too much information.', array( 'status' => 422, ) ); } /* ===================================================== VALID ROLES ====================================================== */ $allowed_roles = array( 'physician' => 'Physician / Doctor', 'research-site' => 'Research Site', 'coordinator' => 'Clinical Research Coordinator', 'sponsor-cro' => 'Sponsor / CRO', 'operations' => 'Research Operations', 'other' => 'Other', ); if (!isset($allowed_roles[$role])) { return new WP_Error( 'rh_demo_invalid_role', 'Please select a valid role.', array( 'status' => 422, ) ); } $role_label = $allowed_roles[$role]; /* ===================================================== VALID TEAM SIZE ====================================================== */ $allowed_team_sizes = array( '' => 'Not provided', '1-5' => '1-5', '6-20' => '6-20', '21-50' => '21-50', '51-plus' => '51+', ); if ( !array_key_exists( $team_size, $allowed_team_sizes ) ) { return new WP_Error( 'rh_demo_invalid_team_size', 'Please select a valid team size.', array( 'status' => 422, ) ); } $team_size_label = $allowed_team_sizes[$team_size]; /* ===================================================== RATE LIMIT MAX 5 SUBMISSIONS / 10 MINUTES / IP ====================================================== */ $ip_address = !empty($_SERVER['REMOTE_ADDR']) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : 'unknown'; $rate_key = 'rh_request_demo_' . md5($ip_address); $submission_count = (int) get_transient( $rate_key ); if ($submission_count >= 5) { return new WP_Error( 'rh_demo_rate_limit', 'Too many demo requests. Please wait a few minutes and try again.', array( 'status' => 429, ) ); } set_transient( $rate_key, $submission_count + 1, 10 * MINUTE_IN_SECONDS ); /* ===================================================== EMAIL RECIPIENTS ====================================================== */ $recipients = array( 'moe@sentrixmedia.com', 'habib@sentrixmedia.com', ); /* ===================================================== EMAIL SUBJECT ====================================================== */ $subject = sprintf( '[Recruitment Hero] New Demo Request - %s %s - %s', $first_name, $last_name, $organization ); /* ===================================================== SUBMISSION DATE ====================================================== */ $submitted_at = current_time( 'F j, Y - g:i A' ); /* ===================================================== SAFE EMAIL VALUES ====================================================== */ $safe_name = esc_html( $first_name . ' ' . $last_name ); $safe_email = esc_html($email); $safe_phone = esc_html( !empty($phone) ? $phone : 'Not provided' ); $safe_organization = esc_html($organization); $safe_role = esc_html($role_label); $safe_team_size = esc_html($team_size_label); $safe_submitted_at = esc_html($submitted_at); $safe_message = !empty($message) ? nl2br( esc_html($message) ) : 'No additional message provided.'; /* ===================================================== EMAIL BODY ====================================================== */ $email_body = '
RECRUITMENT HERO
New Demo Request

A new Request a Demo form has been submitted through the Recruitment Hero website.

Name ' . $safe_name . '
Work Email ' . $safe_email . '
Phone ' . $safe_phone . '
Organization ' . $safe_organization . '
Role ' . $safe_role . '
Team Size ' . $safe_team_size . '
Submitted ' . $safe_submitted_at . '
What would they like to learn about?
' . $safe_message . '
Reply directly to this email to contact ' . esc_html($first_name) . ' at ' . $safe_email . '.
'; /* ===================================================== EMAIL HEADERS ====================================================== */ $headers = array( 'Content-Type: text/html; charset=UTF-8', sprintf( 'Reply-To: %s %s <%s>', $first_name, $last_name, $email ), ); /* ===================================================== SEND EMAIL ====================================================== */ $sent = wp_mail( $recipients, $subject, $email_body, $headers ); /* ===================================================== EMAIL FAILED ====================================================== */ if (!$sent) { return new WP_Error( 'rh_demo_mail_failed', 'Your demo request could not be sent right now. Please try again.', array( 'status' => 500, ) ); } /* ===================================================== SUCCESS RESPONSE ====================================================== */ return new WP_REST_Response( array( 'success' => true, 'message' => 'Thank you! Your demo request has been submitted successfully. Our team will contact you soon.', ), 200 ); } /* ========================================================= EMAIL LABEL STYLE ========================================================= */ function rh_request_demo_label_style() { return ' width:145px; padding:11px 12px; border-bottom:1px solid #edf1f5; background:#f8fbfe; color:#082d75; font-weight:600; vertical-align:top; '; } /* ========================================================= EMAIL VALUE STYLE ========================================================= */ function rh_request_demo_value_style() { return ' padding:11px 12px; border-bottom:1px solid #edf1f5; color:#52657f; vertical-align:top; '; } Page not found – Recruitment Hero

It looks like the link pointing here was faulty. Maybe try searching?

Scroll to Top