Is it possible to extend the FeinCMS contact form to have extra fields?

208 views
Skip to first unread message

littlejim84

unread,
Sep 5, 2010, 2:37:22 PM9/5/10
to Django FeinCMS
Hello.

I'm using the FeinCMS contact form in a number of small websites. But
I'm curious to know if I can have more fields in them, or possibly
take some away? For example, the subject field is not really needed in
most of the contact forms I do. Also, in other ones I've adding around
the place (such as booking forms) they require additional fields to be
added to the form.

What is the procedure to extend/modify the FeinCMS contact form
content type?

Sorry for all the questions recently, I'm not an expert at this, and
there is just a few small things I need to know which will then extend
my knowledge into various other areas.

Many thanks, Jim

Simon Meers

unread,
Sep 5, 2010, 4:55:41 PM9/5/10
to django-feincms
Sure, just follow the instructions here [1] regarding building your own content types, and copy whatever you like from the example contact form type.

[1] http://www.feinheit.ch/media/labs/feincms/contenttypes.html


--
You received this message because you are subscribed to the Google Groups "Django FeinCMS" group.
To post to this group, send email to django-...@googlegroups.com.
To unsubscribe from this group, send email to django-feincm...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-feincms?hl=en.


Matthias Kestenholz

unread,
Sep 6, 2010, 3:30:04 AM9/6/10
to django-...@googlegroups.com
On Sun, Sep 5, 2010 at 10:55 PM, Simon Meers <drm...@gmail.com> wrote:
> Sure, just follow the instructions here [1] regarding building your own
> content types, and copy whatever you like from the example contact form
> type.
>
> [1] http://www.feinheit.ch/media/labs/feincms/contenttypes.html
>

That's correct -- the bundled contact form content type is more of an
example than a ready-to-use content type.

The ContactFormContent allows you to replace the used
django.forms.Form subclass, but ContactFormContent.render is currently
quite dependant on the presence of at least an email and a subject
field in form.cleaned_data, which sucks a bit.

I'm not too interested in fixing ContactFormContent, at least not in
backwards incompatible ways. I think the form_designer ideas are much
more interesting:
http://github.com/matthiask/form_designer

Thanks
Matthias

littlejim84

unread,
Sep 6, 2010, 5:16:55 PM9/6/10
to Django FeinCMS
Whats the idea behind this form designer?

Is it what I think, you can design forms in the admin area? Is it
production ready at all?

(sorry can't test it out at the moment)

What's the deal with this? Sounds interesting.




On Sep 6, 8:30 am, Matthias Kestenholz <matthias.kestenh...@gmail.com>
wrote:

Matthias Kestenholz

unread,
Sep 7, 2010, 3:38:16 AM9/7/10
to django-...@googlegroups.com
On Mon, Sep 6, 2010 at 11:16 PM, littlejim84 <james.mo...@gmail.com> wrote:
> Whats the idea behind this form designer?
>
> Is it what I think, you can design forms in the admin area? Is it
> production ready at all?
>
> (sorry can't test it out at the moment)
>
> What's the deal with this? Sounds interesting.
>

Yeah, documentation is (obviously) sorely lacking currently.

The idea is this:

* An administrator defines a form with all fields contained (f.e.
name, email, question for a question form)
* The FormContent content type is used to display the form somewhere
on a FeinCMS-managed page
* A selection of developer-defined actions is available upon form
submission. F.e. sending an e-mail, sending a SMS, incrementing a
counter somewhere etc., whatever you like


The first two points are working in production right now. The third
point isn't fully implemented yet -- the e-mail sending action is
hardcoded right now, but this can be easily changed; the hard code is
all written.


Matthias

hejsan

unread,
Oct 22, 2010, 2:23:50 PM10/22/10
to Django FeinCMS
Hi.
As a recent feincms convert (from django-page-cms) I'd like to share a
custom form I made to receive enquiries from potential customers.
Upon submit a confirmation email is sent to both the site owner and
the customer.
I'd like to note that instead of putting my content types into
models.py I decided it would be cleaner to have a cms.py file for that
stuff. I then make sure to import cms.py from the models.py file.

The Enquiry model could be any standard django model class you create,
and EnquiryForm is just a normal ModelForm connected to the Enquiry
model.

Caveats: It should be possible to return a HttpResponseRedirect
because that is standard behavior when submitting forms. Perhaps you
could allow for that Matthias? Just check if what is returned from
render is of instance of HttpResponseRedirect and then you pass on the
redirection.

# enquiry/models.py
# -*- coding: utf-8 -*-
from django.db import models
from django.utils.translation import ugettext_lazy as _

class HandymanType(models.Model):
name = models.CharField(max_length=50)
def __unicode__(self):
return self.name
class Meta:
verbose_name = _(u'Handyman type')
verbose_name_plural = _(u'Handyman types')


# class Handyman(models.Model):
# name = models.CharField(max_length=120)

class Enquiry(models.Model):
name = models.CharField(max_length=100,
verbose_name=_(u"Name"), help_text=_(u"Your or your company's name"))
address = models.CharField(max_length=200,
verbose_name=_(u"Address"), help_text=_(u"Please write street name and
number"))
postal_code = models.CharField(max_length=10,
verbose_name=_(u"Postal code"))
town = models.CharField(max_length=50,
verbose_name=_(u"Town/City"))
phone = models.CharField(max_length=32,
verbose_name=_(u"Telephone"), null=True, blank=True)
email = models.EmailField(verbose_name=_(u"Email Address"),
null=True, blank=True)
handy_type = models.ManyToManyField(HandymanType,
verbose_name=_(u"What kind of handyman do you need?"), null=True,
blank=True)
details = models.TextField(verbose_name=_(u"Details about
assignment"), null=True, blank=True)
def __unicode__(self):
return self.name
def get_handy_types(self):
retval = u""
try:
retval = u", ".join(x.__unicode__() for x in
self.handy_type.all())
except:
pass
return retval

class Meta:
verbose_name = _(u'Enquiry')
verbose_name_plural = _(u'Enquiries')

# enquiry/forms.py
# -*- coding: utf-8 -*-
from django.forms import ModelForm
from handverkere.enquiry.models import Enquiry

class EnquiryForm(ModelForm):
class Meta:
model = Enquiry

# enquiry/admin.py
from django.contrib import admin
from handverkere.enquiry.models import *
admin.site.register(Enquiry)
admin.site.register(HandymanType)


# enquiry/cms.py
# -*- coding: utf-8 -*-
from django.template import RequestContext
from django.template.loader import render_to_string
from django.utils.translation import ugettext_lazy as _
from django.core.mail import EmailMessage
from django.db import models
from mysite.enquiry.models import Enquiry
from mysite.enquiry.forms import EnquiryForm


class EnquiryContent(models.Model):
form = EnquiryForm

@classmethod
def initialize_type(cls, form=None):
if form:
cls.form = form

def render(self, **kwargs):
request = kwargs.get('request')

if request.method == 'POST':
form = self.form(request.POST)

if form.is_valid():
enquiry = form.save()
try:
confirmation = render_to_string('emails/
enquiry_confirmation_email.txt', { 'enquiry': enquiry } )
subject = _(u"%s - My sites name enquiry
received") % enquiry.name
email = EmailMessage(subject, confirmation,
bcc=['in...@mysite.net'], to=[enquiry.email])
email.send()
except Exception, inst:
pass # You should probably log the error
# return HttpResponseRedirect('/thankyou/') # Redirect
after POST
return render_to_string('content/enquiryform/
thanks.html')
else:
form = EnquiryForm()

return render_to_string('content/enquiryform/form.html', {
'content': self,
'form': form,
}, context_instance=RequestContext(request))
class Meta:
abstract = True
verbose_name = _(u'Enquiry form')
verbose_name_plural = _(u'Enquiry forms')

from feincms.module.page.models import Page
Page.create_content_type(EnquiryContent)


I hope this helps someone.
regards,
hejsan


On Sep 7, 7:38 am, Matthias Kestenholz <matthias.kestenh...@gmail.com>
wrote:

M M Rahman

unread,
Feb 20, 2013, 7:55:18 AM2/20/13
to django-...@googlegroups.com
Hi hejsan,

Can you kindly provide an example of the HttpResponseRedirect from the feincms content block.


Kind Regards,
M M Rahman
Reply all
Reply to author
Forward
0 new messages