Make your form to work
If form is submited, all form data are send to you as telegram Message
Click here for quick demo
<script src="https://cdn.jsdelivr.net/gh/yogeshwaran01/formBot.js@1.2.0/formBot.min.js" ></script>
In index.html
- Name the id of your form as
formBot
- set new attribute
names
. value ofnames
is name of all input elements eg:name="name mail message"
. Here name, mail, messgage are the value ofname
attribute of input elements. - set other attribute
chatId
of your telegram. Get chat id from Telegram Bot.
<form id="formBot" names="name mail message" chatId="104753182211">
<label for="name">Name</label>
<input type="text" name="name">
<label for="mail">Mail</label>
<input type="text" name="mail">
<label for="message">Message</label>
<input type="text" name="message">
<input type="submit">
</form>
- Finally add
script
tag to make the form Work
<script>
document.getElementById('formBot').onsubmit = (e) =>{
sendMessage(e)
}
</script>
The full html is
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Contact Form</title>
<script src="https://cdn.jsdelivr.net/gh/yogeshwaran01/formBot.js@1.0.0/formBot.min.js" ></script>
</head>
<body>
<form id="formBot" names="name mail message" chatId="your_chat_id">
<label for="name">Name</label>
<input type="text" name="name">
<label for="mail">Mail</label>
<input type="text" name="mail">
<label for="message">Message</label>
<input type="text" name="message">
<input type="submit">
</form>
<script>
document.getElementById('formBot').onsubmit = (e) =>{
sendMessage(e)
}
</script>
</body>
</html>
That it, The form is now working
By default, it targets form with id formBot
, you can change it with your own id
document.getElementById('your_own_id').onsubmit = (e) =>{
sendMessage(e, {'formId': 'your_own_id'})
}
chatId of your telegram can be mention in html or js
<form id="formBot" names="name mail message" chatId="your_chat_id">
or
document.getElementById('your_own_id').onsubmit = (e) =>{
sendMessage(e, {'chatId': 'your_chat_id'})
}
- Report any bugs in issues section
- Create pull request if you fix any bugs or added new fetures