-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathembed-form.js
More file actions
37 lines (30 loc) · 1.11 KB
/
embed-form.js
File metadata and controls
37 lines (30 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Generate an embeddable form snippet using FormForge API
// Usage: node embed-form.js
const formDefinition = {
title: 'Newsletter Signup',
theme: 'playful',
fields: [
{ name: 'email', type: 'email', label: 'Email Address', required: true },
{ name: 'name', type: 'text', label: 'First Name' },
{ name: 'interests', type: 'select', label: 'I am interested in', options: ['APIs', 'Web Development', 'Data Tools', 'All of the above'] }
]
};
async function generateEmbed() {
const res = await fetch('https://formforge-api.vercel.app/api/json-to-embed', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formDefinition)
});
if (!res.ok) {
console.error(`Error: ${res.status}`);
process.exit(1);
}
const result = await res.json();
console.log('=== Embed Code ===');
console.log('Copy this snippet into any HTML page:\n');
console.log(result.embed || result.html);
const fs = await import('fs');
fs.writeFileSync('embed-form.html', result.embed || result.html);
console.log('\nEmbed snippet saved to embed-form.html');
}
generateEmbed();