Contact Form JS,CSS,HTML

 script.gs


function doPost(e) {

  // Google Sheet का ID और नाम

  var sheet = SpreadsheetApp.openById('1Kf6jiWkYN1U2NFQa62tCtgfCJq6qYtj0hDOpq5SFg').getSheetByName('Sheet1'); // "Sheet1" नाम की Sheet


  // Form data को प्राप्त करना

  var params = e.parameter;


  // डेटा को Sheet में add करना

  sheet.appendRow([params.name, params.contact, params.address, params.favoriteCourse]);


  // Success message return करना

  return ContentService.createTextOutput("Data Saved Successfully");

}


function doGet() {

  return HtmlService.createHtmlOutput("Submit the form.");

}


script.gs




index


<!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>

    <style>

        body {

            font-family: Arial, sans-serif;

            margin: 0;

            padding: 20px;

            background-color: #f4f4f4;

        }

        h1 {

            text-align: center;

            color: #333;

        }

        form {

            max-width: 600px;

            margin: 0 auto;

            padding: 20px;

            background-color: #fff;

            border-radius: 8px;

            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);

        }

        label {

            font-weight: bold;

            margin-top: 10px;

        }

        input, textarea, select {

            width: 100%;

            padding: 10px;

            margin-top: 5px;

            margin-bottom: 10px;

            border: 1px solid #ccc;

            border-radius: 4px;

            box-sizing: border-box;

        }

        button {

            background-color: #4CAF50;

            color: white;

            padding: 12px 20px;

            border: none;

            border-radius: 4px;

            cursor: pointer;

            font-size: 16px;

            width: 100%;

        }

        button:hover {

            background-color: #45a049;

        }

        .success-message {

            color: green;

            font-weight: bold;

            text-align: center;

        }

        .error-message {

            color: red;

            font-weight: bold;

            text-align: center;

        }

        .loading-message {

            text-align: center;

            font-size: 18px;

            color: #ff9900;

            font-weight: bold;

        }

    </style>

</head>

<body>

    <h1>Contact Form</h1>

    <form id="contactForm">

        <label for="name">Your Name:</label>

        <input type="text" id="name" name="name" required><br><br>


        <label for="contact">Your Contact:</label>

        <input type="tel" id="contact" name="contact" required><br><br>


        <label for="message">Your Massage:</label><br>

        <textarea id="message" name="address" rows="4" placeholder="अपना पता लिख सकते है या आप हमसे कोई प्रश्न पूछ सकते है " required></textarea><br><br>


        <label for="favoriteCourse">Select Your Favorite Course:</label>

        <select id="favoriteCourse" name="favoriteCourse" required>

            <option value="">Choose One</option>

            <option value="ADCA">ADCA</option>

            <option value="DCA">DCA</option>

            <option value="CCA">CCA</option>

            <option value="CCC">CCC</option>

            <option value="CCFA">CCFA</option>

            <option value="WEB DESIGNING">WEB DESIGNING</option>

            <option value="TALLY">TALLY</option>

        </select><br><br>

        <label for="reason">Reson:</label>

        <input type="text" id="reason" name="reason" required><br><br>



        <button type="submit">Submit</button>

    </form>


    <div id="responseMessage" class="success-message"></div>

    <div id="loadingMessage" class="loading-message" style="display: none;">Processing...</div>


    <script>

        const scriptURL = "https://script.google.com/macros/s/AKfycbx2c0-OZuzqE0IB-09pYc2aJTdgCoPJb6VcLmdy4D8YUW94PVtkQCz8YvF7MF2CX6/exec";  // Web App URL

        const form = document.getElementById('contactForm');

        const responseMessage = document.getElementById('responseMessage');

        const loadingMessage = document.getElementById('loadingMessage');


        form.addEventListener('submit', e => {

            e.preventDefault(); // Form submit होने से पहले default action रोका


            // Show loading message

            loadingMessage.style.display = 'block';


            const formData = new FormData(form); // Form data ले रहे हैं


            // API Call (POST request)

            fetch(scriptURL, { method: 'POST', body: formData })

                .then(response => {

                    loadingMessage.style.display = 'none'; // Hide loading message

                    responseMessage.textContent = "Form submitted successfully!"; // Success message

                    responseMessage.className = "success-message"; // Apply success styling

                    form.reset(); // Reset form after successful submission

                })

                .catch(error => {

                    loadingMessage.style.display = 'none'; // Hide loading message

                    responseMessage.textContent = "Error submitting the form! Please try again."; // Error message

                    responseMessage.className = "error-message"; // Apply error styling

                });

        });

    </script>

</body>

</html>


index

Previous Post Next Post