How to

Whatsapp Contact Form Source Code Html CSS Javascript

Ravindra Kumar
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Contact Form</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
  <style>
    body {
      background-color: #f8f9fa;
    }
    .contact-form {
      max-width: 600px;
      margin: 50px auto;
      padding: 20px;
      background: #fff;
      border-radius: 10px;
      box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    }
  </style>
</head>
<body>
  <div class="container">
    <div class="contact-form">
      <h2 class="text-center mb-4">Contact Us</h2>
      <form id="contactForm">
        <div class="mb-3">
          <label for="name" class="form-label">Name</label>
          <input type="text" class="form-control" id="name" placeholder="Your Name" required>
        </div>
        <div class="mb-3">
          <label for="email" class="form-label">Email</label>
          <input type="email" class="form-control" id="email" placeholder="Your Email" required>
        </div>
        <div class="mb-3">
          <label for="mobile" class="form-label">Mobile Number</label>
          <input type="text" class="form-control" id="mobile" placeholder="Your Mobile Number" required>
        </div>
        <div class="mb-3">
          <label for="subject" class="form-label">Subject</label>
          <input type="text" class="form-control" id="subject" placeholder="Subject" required>
        </div>
        <div class="mb-3">
          <label for="query" class="form-label">Your Query</label>
          <textarea class="form-control" id="query" rows="4" placeholder="Your Query" required></textarea>
        </div>
        <button type="button" class="btn btn-primary w-100" onclick="sendToWhatsApp()">Submit</button>
      </form>
    </div>
  </div>

  <script>
    function sendToWhatsApp() {
      // Retrieve form data
      const name = document.getElementById('name').value;
      const email = document.getElementById('email').value;
      const mobile = document.getElementById('mobile').value;
      const subject = document.getElementById('subject').value;
      const query = document.getElementById('query').value;

      // WhatsApp number where the message should be sent
      const whatsappNumber = "1234567890"; // Replace with your WhatsApp number

      // Construct the WhatsApp message
      const message = `Hello, I would like to contact you:%0A%0A` +
        `*Name:* ${name}%0A` +
        `*Email:* ${email}%0A` +
        `*Mobile:* ${mobile}%0A` +
        `*Subject:* ${subject}%0A` +
        `*Query:* ${query}`;

      // Open WhatsApp Web with the pre-filled message
      const whatsappUrl = `https://wa.me/${whatsappNumber}?text=${message}`;
      window.open(whatsappUrl, '_blank');
    }
  </script>
</body>
</html>

Explanation

  1. Bootstrap Form: The form is styled using Bootstrap classes.
  2. JavaScript Function: The sendToWhatsApp() function retrieves the form data, formats it into a WhatsApp message, and opens WhatsApp Web with the pre-filled message using https://wa.me/.
  3. WhatsApp API: Replace 1234567890 with your WhatsApp number (in international format, without the + or leading zeros).
  4. Validation: The form includes basic validation using the required attribute.

How It Works

  1. The user fills out the form and clicks “Submit.”
  2. The sendToWhatsApp() function gathers the input values.
  3. The browser opens a new tab with WhatsApp Web, pre-filled with the user’s message.

This approach ensures the user’s input is sent directly to WhatsApp without requiring a backend server.

Whatsapp Form Code Generator Tool

Ravindra Kumar

Ravindra is a passionate full stack developer and dedicated blogger with a flair for crafting user-friendly web applications and insightful articles. With expertise spanning front-end and back-end technologies, Ravindra brings ideas to life through innovative coding solutions.

Suggested Reading

How to Create a WhatsApp Form on WordPress Using Ravindra Chat Form Plugin

WhatsApp has become the fastest way for customers to contact businesses online. Instead of waiting for emails or filling long contact forms, users prefer instant messaging. That’s why adding a WhatsApp form on your WordPress website is a smart move for lead generation and customer engagement. In this guide, you’ll learn how to create a […]

Whatsapp Contact Form Source Code Html CSS Javascript

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Contact Form</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <style> body { background-color: #f8f9fa; } .contact-form { max-width: 600px; margin: 50px auto; padding: 20px; background: #fff; border-radius: 10px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); } </style> </head> <body> <div class="container"> <div class="contact-form"> <h2 class="text-center mb-4">Contact Us</h2> […]

Making WhatsApp Order Form using HTML, CSS, Javascript

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Order Form</title> <!-- Bootstrap CSS --> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous"> <script> function sendOrderToWhatsApp() { // Retrieve form values var name = document.getElementById('name').value; var email = document.getElementById('email').value; var contact = document.getElementById('contact').value; var address = document.getElementById('address').value; var pincode = document.getElementById('pincode').value; var landmark = document.getElementById('landmark').value; // Retrieve product selections var […]

Download Free Accessories Ecommerce Store Website Template Using HTML, CSS, JS

Create a Beautiful Online Store for Belts, Hats & Scarves This free accessories store homepage template is crafted for fashion brands that sell belts, hats, scarves, jewelry, or other stylish add-ons.With a sleek design and responsive layout, it’s ideal for showcasing your accessory collections in a clean and professional way. Template Features Fully responsive and […]

Ecommerce Website Frontend source Code in HTML,CSS,Javascript & Bootstrap

Front-end source code makes up an eCommerce website’s UI. This code is crucial to buyer-site interaction.  It includes the structural, visual, and engaging parts that make the user’s experience unique. Online shopping Website frontend source code was created with HTML, CSS, JavaScript, and different frameworks, ensuring the website works and looks good. HTML: Structuring the Web Pages […]

Free Download Books, Stationery & Art Supplies Website Template – HTML, CSS, JS

Create an engaging online presence for your bookstore, stationery shop, craft store, or art supplies brand with our beautifully designed Books, Stationery & Art Supplies Website Template. This template combines clean layouts, warm aesthetics, and user-friendly navigation to help you showcase your products in the most appealing way. Whether you’re selling books, journals, office supplies, […]

Download Free Food & Grocery Website Template using HTML, CSS, JS

Create a Modern and Responsive Online Store for Food, Grocery, or Organic Products This Food & Grocery Website Template is ideal for supermarkets, organic food brands, local grocery shops, restaurants, or farm-to-table businesses looking to go digital.It’s fast, responsive, and beautifully structured to help your customers shop with ease. 🥗 Template Features Fully responsive and […]

How to submit HTML Form to WhatsApp | Sending Form fields to WhatsApp Using HTML,CSS and Javascript

Whatsapp Form Code Generator Tool In this post I am going to explain how can we submit HTML form to WhatsApp. By using this functionality form’s data will be summited to chat interface of WhatsApp, As normally we chat on WhatsApp. This example will tell you about sending form fields to WhatsApp by using JavaScript. […]

Responsive Landing page source code in Html, CSS and Bootstrape

Landing pages are a critical element of any online marketing strategy. They are designed to capture leads, promote products, and convert visitors into customers. To create a compelling landing page, you don’t need to be an expert coder. With HTML, CSS, and Bootstrap, you can design a professional, responsive, and user-friendly landing page. In this […]