Vue.js Quiz Form Generator

Build interactive quizzes and assessments

Back to Generator

Form Preview

Vue.js Code

<template>
  <div class="form-container">
    <form @submit.prevent="handleSubmit">
      <div class="form-group">
        <label for="name" class="required">Your Name</label>
        <input
          type="text"
          id="name"
          v-model="formData.name"
          required
        />
      </div>
      <div class="form-group">
        <label for="email" class="required">Email Address</label>
        <input
          type="email"
          id="email"
          v-model="formData.email"
          required
        />
      </div>
      <div class="form-group">
        <label for="question1" class="required">Question 1: What is the capital of France?</label>
        <div class="radio-group">
          <div class="radio-item">
            <input
              type="radio"
              id="question1-0"
              v-model="formData.question1"
              value="London"
              required
            />
            <label for="question1-0">London</label>
          </div>
          <div class="radio-item">
            <input
              type="radio"
              id="question1-1"
              v-model="formData.question1"
              value="Berlin"
              
            />
            <label for="question1-1">Berlin</label>
          </div>
          <div class="radio-item">
            <input
              type="radio"
              id="question1-2"
              v-model="formData.question1"
              value="Paris"
              
            />
            <label for="question1-2">Paris</label>
          </div>
          <div class="radio-item">
            <input
              type="radio"
              id="question1-3"
              v-model="formData.question1"
              value="Madrid"
              
            />
            <label for="question1-3">Madrid</label>
          </div>
        </div>
      </div>
      <div class="form-group">
        <label for="question2" class="required">Question 2: Which planet is closest to the sun?</label>
        <div class="radio-group">
          <div class="radio-item">
            <input
              type="radio"
              id="question2-0"
              v-model="formData.question2"
              value="Earth"
              required
            />
            <label for="question2-0">Earth</label>
          </div>
          <div class="radio-item">
            <input
              type="radio"
              id="question2-1"
              v-model="formData.question2"
              value="Venus"
              
            />
            <label for="question2-1">Venus</label>
          </div>
          <div class="radio-item">
            <input
              type="radio"
              id="question2-2"
              v-model="formData.question2"
              value="Mercury"
              
            />
            <label for="question2-2">Mercury</label>
          </div>
          <div class="radio-item">
            <input
              type="radio"
              id="question2-3"
              v-model="formData.question2"
              value="Mars"
              
            />
            <label for="question2-3">Mars</label>
          </div>
        </div>
      </div>
      <div class="form-group">
        <label for="question3" class="required">Question 3: Who painted the Mona Lisa?</label>
        <div class="radio-group">
          <div class="radio-item">
            <input
              type="radio"
              id="question3-0"
              v-model="formData.question3"
              value="Van Gogh"
              required
            />
            <label for="question3-0">Van Gogh</label>
          </div>
          <div class="radio-item">
            <input
              type="radio"
              id="question3-1"
              v-model="formData.question3"
              value="Picasso"
              
            />
            <label for="question3-1">Picasso</label>
          </div>
          <div class="radio-item">
            <input
              type="radio"
              id="question3-2"
              v-model="formData.question3"
              value="Da Vinci"
              
            />
            <label for="question3-2">Da Vinci</label>
          </div>
          <div class="radio-item">
            <input
              type="radio"
              id="question3-3"
              v-model="formData.question3"
              value="Michelangelo"
              
            />
            <label for="question3-3">Michelangelo</label>
          </div>
        </div>
      </div>
      <div class="form-group">
        <button type="submit">Submit</button>
      </div>
    </form>
  </div>
</template>

<script>
export default {
  name: 'QuizForm',
  data() {
    return {
      formData: {
        name: '',
        email: '',
        question1: '',
        question2: '',
        question3: '',
      }
    };
  },
  methods: {
    handleSubmit() {
      console.log('Form submitted with data:', this.formData);
      // You would typically send this data to an API here
      alert('Form submitted successfully!');
    }
  }
};
</script>

<style scoped>
.form-container {
  max-width: 600px;
  margin: 0 auto;
  background: #f9f9f9;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.form-group {
  margin-bottom: 15px;
}

label {
  display: block;
  margin-bottom: 5px;
  font-weight: bold;
}

.required:after {
  content: " *";
  color: red;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  box-sizing: border-box;
  font-size: 16px;
}

textarea {
  height: 100px;
}

.checkbox-group, .radio-group {
  margin-bottom: 10px;
}

.checkbox-item, .radio-item {
  margin-bottom: 5px;
}

button {
  background-color: #4CAF50;
  color: white;
  padding: 10px 15px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 16px;
}

button:hover {
  background-color: #45a049;
}
</style>

Installation

How to setup Vue.js Quiz form

  1. 1

    Sign up to parrotforms.com

    Create your first form API endpoint then copy your endpoint.

    Screenshot Placeholder
  2. 2

    Copy the example code

    Use the copy button above to copy the entire code snippet.

    Screenshot Placeholder
  3. 3

    Paste the code and update the endpoint

    Replace the form API endpoint with the one you got in step 1.

    Screenshot Placeholder
  4. 4

    Collect submissions

    View and manage all form submissions in your parrotForms dashboard.

    Screenshot Placeholder

Need more advanced forms?

Create a free parrotForms account to access more templates, save your forms, and collect submissions.

Create a Free Account