-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsurvey-form.js
More file actions
40 lines (34 loc) · 1.69 KB
/
survey-form.js
File metadata and controls
40 lines (34 loc) · 1.69 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
38
39
40
// Generate a survey form with multiple field types using FormForge API
// Usage: node survey-form.js
const surveyDefinition = {
title: 'Customer Satisfaction Survey',
theme: 'corporate',
fields: [
{ name: 'name', type: 'text', label: 'Your Name' },
{ name: 'email', type: 'email', label: 'Email (for follow-up)', required: true },
{ name: 'product', type: 'select', label: 'Which product did you use?', options: ['DocForge API', 'ReportForge API', 'FormForge API'], required: true },
{ name: 'rating', type: 'select', label: 'Overall Rating', options: ['5 - Excellent', '4 - Good', '3 - Average', '2 - Below Average', '1 - Poor'], required: true },
{ name: 'ease_of_use', type: 'select', label: 'Ease of Integration', options: ['Very Easy', 'Easy', 'Moderate', 'Difficult', 'Very Difficult'] },
{ name: 'recommend', type: 'radio', label: 'Would you recommend us?', options: ['Yes', 'No', 'Maybe'] },
{ name: 'newsletter', type: 'checkbox', label: 'Subscribe to product updates' },
{ name: 'feedback', type: 'textarea', label: 'Additional Feedback' }
]
};
async function generateSurvey() {
const res = await fetch('https://formforge-api.vercel.app/api/json-to-form', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(surveyDefinition)
});
if (!res.ok) {
console.error(`Error: ${res.status}`);
process.exit(1);
}
const { html } = await res.json();
const fs = await import('fs');
fs.writeFileSync('survey-form.html', html);
console.log('Survey form saved to survey-form.html');
console.log(`Fields: ${surveyDefinition.fields.length}`);
console.log(`Theme: ${surveyDefinition.theme}`);
}
generateSurvey();