Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Guides] Update the 'Submit web forms directly to bots in Cerb' guide from behaviors to automations #96

Open
cerb opened this issue Jan 13, 2025 · 1 comment

Comments

@cerb
Copy link
Owner

cerb commented Jan 13, 2025

See: https://cerb.ai/guides/webhooks/html-form-submit/

This guide uses bot behaviors and needs to be updated to automations/workflows.

The embedded jsFiddle should make this easy to test.

ngrok can be used to temporarily expose your local Docker instance to third-party apps:
https://cerb.ai/guides/developers/ngrok/

@jstanden
Copy link
Collaborator

It needs like a jsFiddle with plain HTML + Javascript, showing a form posting into a webhook.

GPT4o example:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Webhook Form</title>
    <script>
        function sendRequest(event) {
            event.preventDefault(); // Prevent form submission
            
            var xhr = new XMLHttpRequest();
            var url = "https://your-webhook-url.com"; // Replace with your webhook URL
            xhr.open("POST", url, true);
            xhr.setRequestHeader("Content-Type", "application/json");
            
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    var responseContainer = document.getElementById("response");
                    if (xhr.status === 200) {
                        var response = JSON.parse(xhr.responseText);
                        responseContainer.innerHTML = "<p style='color: green;'>Success: " + response.message + "</p>";
                    } else {
                        responseContainer.innerHTML = "<p style='color: red;'>Error: " + xhr.statusText + "</p>";
                    }
                }
            };
            
            var data = JSON.stringify({
                name: document.getElementById("name").value,
                email: document.getElementById("email").value
            });
            
            xhr.send(data);
        }
    </script>
</head>
<body>
    <h2>Submit Data</h2>
    <form onsubmit="sendRequest(event)">
        <label for="name">Name:</label>
        <input type="text" id="name" name="name" required>
        <br>
        <label for="email">Email:</label>
        <input type="email" id="email" name="email" required>
        <br>
        <button type="submit">Submit</button>
    </form>
    <div id="response"></div>
</body>
</html>

You can put that in a jsFiddle or just a blah.html file in your local filesystem opened by the browser.

That shouldn't need ngrok to access your local Cerb webhook URL for testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants