I have a designed form in my template and i want to use it instead of Django Forms. I created my model and view class and urls, but I don't know how to receive and use form's data. I've already studied Rendering fields manually but I want to use my form inputs and labels and only need the data.
Please be aware that class and models work perfectly and I can use data if I use {{ form }} in my template instead of html code below
Here's my class in my forms.py:
class Reserve(forms.Form):
name = forms.CharField(label='نام و نام خانوادگی', max_length=100)
phone = forms.CharField(label='شماره تماس', max_length=11)
email = forms.EmailField(label='ایمیل', max_length=100)
occasion = forms.CharField(label='مناسبت', max_length=100)
month = forms.CharField(label='ماه', max_length=100)
day = forms.CharField(label='روز', max_length=100)
week = forms.CharField(label='روز هفته')
time = forms.CharField(label='ساعت', max_length=100)
message = forms.CharField(label='توضیحات')
Here's my function in views.py:
def add_reserve(request):
if request.method == 'POST':
form = Reserve(request.POST)
if form.is_valid():
name = form.cleaned_data['name']
phone = form.cleaned_data['phone']
email = form.cleaned_data['email']
occasion = form.cleaned_data['occasion']
month = form.cleaned_data['month']
day = form.cleaned_data['day']
week = form.cleaned_data['week']
time = form.cleaned_data['time']
message = form.cleaned_data['message']
reserve = MangReserve(name=name, phone=phone, email=email, occasion=occasion, month=month, day=day,
week=week, time=time, message=message)
reserve.save()
return HttpResponseRedirect('/')
else:
form = Reserve()
return render(request, 'mang/temp.html', {'form': form})
And finally a part of my form:
<form method="post" action="{% url 'mang:add-reserve' %}">
{% csrf_token %}
<div class="form-group ">
<label for="name" class="sr-only">Name</label>
<input id="name" class="form-control" placeholder="نام و نام خانوادگی" type="text">
</div>
<div class="form-group ">
<label for="phone" class="sr-only">Name</label>
<input id="phone" class="form-control" placeholder="موبایل" type="text">
</div>
<div class="form-group ">
<label for="email" class="sr-only">Email</label>
<input id="email" class="form-control" placeholder="ایمیل" type="email">
</div>
<div class="form-group ">
<label for="occasion" class="sr-only">occasion</label>
<input id="occasion" class="form-control" placeholder="مناسبت" type="text">
</div>.......