from django.shortcuts import render
from .forms import ContactForm
from django.contrib import messages

def index(request):
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            form.save()
            messages.success(request, 'Merci! Votre message a été envoyé avec succès.')
            form = ContactForm() # Clear form
    else:
        form = ContactForm()

    context = {
        'form': form
    }
    return render(request, 'core/index.html', context)