voicemenu143 / templates /index.html
DSatishchandra's picture
Update templates/index.html
e5373c3 verified
raw
history blame
2.44 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Biryani Hub Login</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<h1>Welcome to Biryani Hub!</h1>
<p>Please provide your details:</p>
<!-- User Input Form -->
<form id="userDetailsForm">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br><br>
<label for="phone">Phone Number:</label>
<input type="text" id="phone" name="phone" required><br><br>
<button type="submit">Submit</button>
</form>
<div id="responseMessage"></div>
<script>
$(document).ready(function() {
// Handle form submission
$('#userDetailsForm').on('submit', function(event) {
event.preventDefault();
// Get form values
var name = $('#name').val();
var email = $('#email').val();
var phone = $('#phone').val();
// Validate the input
if (!name || !email || !phone) {
$('#responseMessage').text("All fields are required.");
return;
}
// Create an object with the data
var formData = {
name: name,
email: email,
phone: phone
};
// Send the data to the backend via POST request
$.ajax({
url: '/submit', // Backend route to handle data
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(formData),
success: function(response) {
// Handle the success response
$('#responseMessage').text("User registered successfully!");
},
error: function(xhr, status, error) {
// Handle the error response
$('#responseMessage').text("Error: " + xhr.responseJSON.error);
}
});
});
});
</script>
</body>
</html>