This example shows how your AI bot can collect information through conversation and automatically fill a form on your website. The bot gathers data naturally through chat, then sends it back to populate form fields.
Chat with the bot, answer its questions, and watch the form fill automatically
<!-- Bot Container -->
<div id="myLandbot" style="width: 100%; height: 600px"></div>
<!-- Form -->
<form id="contactForm">
<input type="text" id="fullName" placeholder="Full Name">
<input type="email" id="email" placeholder="Email">
<input type="tel" id="phone" placeholder="Phone">
<input type="text" id="company" placeholder="Company">
<textarea id="message" placeholder="Message"></textarea>
<button type="submit">Submit Form</button>
</form>
<!-- Load Landbot SDK -->
<script src="https://cdn.landbot.io/landbot-3/landbot-3.0.0.js"></script>
<script>
// Initialize Landbot Container (embedded bot)
var myLandbot = new Landbot.Container({
container: '#myLandbot',
configUrl: 'YOUR-BOT-CONFIG-URL'
});
</script>
// ⭐ Window function that bot can call to fill the form
window.fillContactForm = function(data) {
console.log('Filling form with data:', data);
// Fill form fields
if (data.name) document.getElementById('fullName').value = data.name;
if (data.email) document.getElementById('email').value = data.email;
if (data.phone) document.getElementById('phone').value = data.phone;
if (data.company) document.getElementById('company').value = data.company;
if (data.message) document.getElementById('message').value = data.message;
// Enable fields and submit button
document.querySelectorAll('#contactForm input, #contactForm textarea').forEach(el => {
el.removeAttribute('readonly');
el.classList.add('filled');
});
document.querySelector('.submit-btn').disabled = false;
};
This is the key! By creating a function on the window object, the bot can call it directly from its flow.
// Inside your Landbot flow, add a Code block to call the window function:
window.fillContactForm({
name: @name,
email: @email,
phone: @phone,
company: @company,
message: @message
});
In your Landbot builder, you need to:
window.fillContactForm() with an object containing the collected data📸 Landbot Code Block - JavaScript Trigger Function
Screenshot showing the Code block that calls window.fillContactForm() with the collected data
document.getElementById('contactForm').addEventListener('submit', function(e) {
e.preventDefault();
// Get form data
const formData = {
fullName: document.getElementById('fullName').value,
email: document.getElementById('email').value,
phone: document.getElementById('phone').value,
company: document.getElementById('company').value,
message: document.getElementById('message').value
};
// Send to your backend
console.log('Submitting form:', formData);
// Show success message
alert('Form submitted successfully!');
});
window.fillContactForm() with collected dataFor this example to work, you need to configure your Landbot to call the window function. This involves:
window.fillContactForm() with collected data📸 Complete Bot Flow Configuration
Screenshot showing the complete bot flow with question blocks that collect user information (name, email, phone, company, message)
This example uses Landbot's AI Agent to have natural conversations with users. The AI Agent needs to be configured to collect specific information during the conversation.
📸 AI Agent Setup & Configuration
Screenshot showing the AI Agent configuration that enables natural conversation-based data collection