- Author:
- zodman
- Posted:
- August 21, 2008
- Language:
- Python
- Version:
- .96
- Tags:
- ajax javascript contact meteora
- Score:
- 0 (after 0 ratings)
This snippets is a simple contact form for use meteora widgets with django
For download the meteora.js and all tools http://meteora.astrata.com.mx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | contact.py on yout root dir of django project
========
from django import forms
from django.utils import simplejson
from django.http import HttpResponse
from django.core.mail import EmailMessage
class ContactForm(forms.Form):
name = forms.CharField(help_text="Your name...")
email = forms.EmailField(help_text="Your email ...",required=True)
message = forms.CharField(widget=forms.Textarea,required=True)
def sendform(request):
form = ContactForm(request.POST)
if request.POST and form.is_valid():
message = {'successMessage':"Yeap it send!"}
data = form.cleaned_data
email_body = " Name %s < %s >\n Message \n %s " %( data['name'], data['email'], data['message'] )
email = EmailMessage(
'contact from %s' % data['name'],
email_body,
to=['[email protected]'],
)
email.send()
else:
message = {
'errorMessage':'Error!!!!',
'execute': "$('form').innerHTML='<table>%s</table>'; " % form.as_table().replace('\n','')
}
return HttpResponse(
simplejson.dumps(message),
mimetype='text/plain'
)
contact.html on your root dir template
====
<script src="/static/meteora/meteora.js" type="text/javascript"></script>
<script>
Meteora.uses('Control.Form');
</script>
<form action="/contacto/sendform/" onsubmit="return formSubmit(this)" method="POST">
<fieldset>
<legend>Send a Message</legend>
<table id="form" class="form">
{{ f }}
</table>
<input type="submit" value="Send">
</fieldset>
</form>
add it to startproject url.py
=====
from yourproject.contact import ContactForm
urlpatterns = blah blah blah
(r'^contacto/$',
'django.views.generic.simple.direct_to_template',
{'template':'contact.html','extra_context':{'f':ContactForm()}}
),
(r'^contacto/sendform/$','yourproject.contact.sendform' ),
|
More like this
- Automatically setup raw_id_fields ForeignKey & OneToOneField by agusmakmun 8 months ago
- Crispy Form by sourabhsinha396 8 months, 3 weeks ago
- ReadOnlySelect by mkoistinen 9 months ago
- Verify events sent to your webhook endpoints by santos22 10 months ago
- Django Language Middleware by agusmakmun 10 months, 2 weeks ago
Comments
Please login first before commenting.