Reputation: 105
model.py
class Client(models.Model):
name = models.CharField(max_length=50)
phone_no = models.CharField(max_length=12)
mail = models.EmailField()
view.py
def create(request):
if request.POST:
form = ClientForm(request.POST)
if form.is_valid():
form.save()
subject = form.cleaned_data['name']
mail = form.cleaned_data['mail']
return HttpResponseRedirect('/')
else:
form = ClientForm()
args = {}
args.update(csrf(request))
args['form'] = form
return render_to_response('save.html', args)
html
<form action="/create/" method="post">{% csrf_token %}
<ul>
{{ form}}
</ul>
<input type="submit" name="submit" value="Create Client">
</form>
</body>
</html>
here i successfully created a form and save the data to db. but i like to sent a mail to the client also. how do get the email directly from the form
Upvotes: 0
Views: 863
Reputation: 1630
In your view code you've got the form data available already, mail = form.cleaned_data['mail']
gives you the email address (if you do a print form.cleaned_data you'll see in your console all the form data.
Upvotes: 1