linuxfront-v2-logistics/inc/panels/contact_our_team.php

Overview

This panel renders and processes the “Contact Our Team” form on the Tech Logistics website. It integrates server-side input sanitization, Google reCAPTCHA v3 protection, and email dispatch via PHP’s mail() function.

Dependencies

  • Configuration: Relies on INFO_EMAIL constant for sender and recipient addresses .
  • Google reCAPTCHA v3: Uses secret key for server-side verification and site key for client-side execution .
  • Frontend Libraries:
    • jQuery
    • jQuery Validate plugin
    • Bootstrap for styling and alerts

Server-Side Processing

This section outlines how the script handles form submissions and protects against bots.

1. Submission Check & Variable Initialization

  • Checks $_POST['action_form'] === 'Submit_form'.
  • Initializes $clear_vars = true to track whether to reset inputs.

2. Input Sanitization

  • Applies strip_tags() to text fields: first name, last name, phone, company, description.
  • Uses filter_var(..., FILTER_SANITIZE_EMAIL) for email.

3. reCAPTCHA v3 Verification

  • Retrieves token from $_POST['g-recaptcha-response'].
  • Sends a POST request to Google’s API via cURL.
  • Checks for cURL errors or HTTP 403 status; on error, sets an access-denied message and flags $clear_vars = false.
  • Decodes JSON response; enforces a score threshold of ≥0.5 to proceed.
flowchart TD
  A[Start: Form Submission] --> B{action_form == 'Submit_form'?}
  B -- No --> O[Render Form]
  B -- Yes --> C[Sanitize Inputs]
  C --> D[Verify reCAPTCHA via cURL]
  D --> E{cURL Error or HTTP 403?}
  E -- Yes --> F[Set "Access Denied" Message]
  E -- No --> G{success & score ≥ 0.5?}
  G -- No --> H[Set "Access Denied" Message]
  G -- Yes --> I[Compose & Send Email]
  I --> J{mail() returns true?}
  J -- Yes --> K[Show Success Notification]
  J -- No --> L[Set Failure Message]
  F & H & L --> M[Do Not Clear Vars]
  K --> N[Clear Vars]
  M & N --> O[Render Form]

4. Email Composition & Dispatch

  • Recipients: INFO_EMAIL constant.
  • Sender: same constant; From Name combines first and last names.
  • Builds HTML body with <strong> labels for clarity.
  • Sets headers for MIME version, content type, From/Reply-To, and X-Mailer.
  • Calls mail($to, $subject, $Body, $headers) and handles success/failure.

5. Input Reset

If $clear_vars remains true, all input variables reset to empty strings to clear form fields.

HTML Structure

This section describes the generated markup and its styling.

Section Wrapper

<section class="container-fluid are-you-looking section-animation" id="contact_out_team">
  <div class="container">...</div>
</section>
  • Uses Bootstrap’s grid system (.row, .col-lg-*).
  • Presents a two-column layout: service description and the form.

Service Description

  • Heading: Do you need Brokerage Services?
  • Paragraph detailing Tech Transport’s brokerage offerings.
  • Centered logo linking back to the contact section.

Form Fields & Layout

Field Type name Attribute Purpose
Hidden Action Field hidden action_form Flags form submission
Hidden reCAPTCHA hidden g-recaptcha-response Holds token from client-side execution
First Name text fName User’s first name
Last Name text lName User’s last name
Phone text company_phone Company phone number
Email text company_email Contact email (validated)
Company Name text company_name User’s company
Detail Description textarea detail_description Detailed inquiry description
Submit Button button — Triggers form validation and submission

Client-Side Logic

The script enhances user experience and security before hitting the server.

1. Google reCAPTCHA v3 Integration

<script src="https://www.google.com/recaptcha/api.js?render=6LexaqwrAAAAAKs-aDNL0G-vBf4mcrVd6I1naxO7" defer async></script>
  • Loads the reCAPTCHA API with the site key.

2. Anti-Paste & Character Blocking

  • Paste Handler: Prevents pasting HTML, CSS, or JavaScript into input fields; shows alert.
  • Keypress Handler: Blocks typing <, >, {, } characters; shows alert.

3. Form Validation (jQuery Validate)

$("#contact_our_team_form").validate({
  rules: {
    fName: { required: true },
    lName: { required: true },
    company_name: { required: true },
    company_email: { required: true, email: true },
    company_phone: { required: true },
    detail_description: { required: true }
  },
  messages: { ... },
  submitHandler: function(form) {
    grecaptcha.ready(function() {
      grecaptcha.execute('6LexaqwrAAAAAKs-aDNL0G-vBf4mcrVd6I1naxO7', { action: 'submit_form' })
        .then(function(token) {
          $('#g-recaptcha-response').val(token);
          form.submit();
        });
    });
  }
});
  • Enforces required fields and valid email syntax.
  • Integrates reCAPTCHA token retrieval before actual submission.

Error & Success Notifications

  • Error Alerts: Uses Bootstrap .alert-danger for access or mail failures.
  • Success Notification: Injects a styled <div> that fades in and out via jQuery.

Emojis for Quick Reference

  • 🛡️ Server-Side Protection
  • ✉️ Email Dispatch
  • 🔒 reCAPTCHA Integration
  • 🖥️ Client-Side Validation

This comprehensive panel ensures secure, user-friendly contact requests with spam protection and immediate feedback.