Skip to content

ContactForm Component ​

Contact form with validation, email integration, and responsive design. Handles user inquiries with proper form validation and email delivery.

Overview ​

The ContactForm component provides a professional contact form for your landing pages. It includes field validation, spam protection, and direct integration with your email system.

Preview ​

Contact Form Component Preview

Basic Usage ​

vue
<template>
  <section class="contact-section">
    <ContactForm />
  </section>
</template>

<script setup lang="ts">
import ContactForm from '@/components/ContactForm.vue'
</script>

Features ​

📝 Form Fields ​

  • Name field with validation
  • Email field with format validation
  • Subject selection dropdown
  • Message textarea with character count
  • Required field indicators

✅ Validation System ​

  • Real-time field validation
  • Email format verification
  • Required field checking
  • Error message display
  • Success confirmation

📧 Email Integration ​

  • Direct email sending capability
  • Template-based email formatting
  • Spam protection measures
  • Delivery confirmation

🎨 Modern Design ​

  • Clean, professional styling
  • Responsive layout design
  • Focus states and animations
  • Accessibility features

Component API ​

Props ​

PropTypeDefaultDescription
titlestring'Contact Us'Form section title
subtitlestringundefinedOptional subtitle text
showSubjectbooleantrueShow subject field
requiredstring[]['name', 'email', 'message']Required fields

Events ​

EventPayloadDescription
submit{ formData }Emitted on form submission
success{ response }Emitted on successful submission
error{ error }Emitted on submission error

Form Fields ​

Field Structure ​

typescript
interface ContactFormData {
  name: string
  email: string
  subject: string
  message: string
  consent: boolean
}

Validation Rules ​

  • Name: Required, minimum 2 characters
  • Email: Required, valid email format
  • Subject: Optional or required based on props
  • Message: Required, minimum 10 characters
  • Consent: Required for GDPR compliance

Styling Details ​

The component uses modern form styling with:

  • Clean input fields with focus states
  • Responsive grid layout
  • Professional typography
  • Consistent spacing and alignment

Integration Examples ​

With Custom Validation ​

vue
<template>
  <ContactForm 
    @submit="handleSubmit"
    @success="handleSuccess"
    @error="handleError"
  />
</template>

<script setup lang="ts">
const handleSubmit = (formData) => {
  // Custom validation logic
}

const handleSuccess = (response) => {
  // Success handling
  toast.success('Message sent successfully!')
}

const handleError = (error) => {
  // Error handling
  toast.error('Failed to send message')
}
</script>

With Custom Fields ​

vue
<ContactForm 
  :required="['name', 'email', 'phone', 'message']"
  :show-subject="false"
  title="Get in Touch"
  subtitle="We'd love to hear from you"
/>

Built with love by mhdevfr