Creating and Using Forms

Steps to Create a New Form

  1. Log in to your 4mform dashboard
  2. Click on the 'Create Form' button
  3. Enter a name for your new form
  4. Click 'Create' to generate your form
  5. Copy the generated Form ID for API usage

Using the API to Submit Form Entries

Once you have created a form, you can use the API to submit entries. Here's an example using JavaScript:

const submitFormEntry = async (formId, apiKey, formData) => {
  const response = await fetch(`https://4mform.tech/api/forms/${formId}/entries`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${apiKey}`
    },
    body: JSON.stringify(formData)
  });

  if (!response.ok) {
    throw new Error('Failed to submit form entry');
  }

  return await response.json();
};

// Example usage
const formId = 'your-form-id';
const apiKey = 'your-api-key';
const formData = {
  name: 'John Doe',
  email: 'john@example.com',
  message: 'Hello, world!'
};

submitFormEntry(formId, apiKey, formData)
  .then(result => console.log('Form entry submitted:', result))
  .catch(error => console.error('Error:', error));

Remember to replace 'your-form-id' and 'your-api-key' with your actual Form ID and API Key. The formData object should contain the fields specific to your form.