Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6162693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:41:49+00:00 2026-05-23T21:41:49+00:00

Using django-contact-form , I have overridden the form class: from contact_form.forms import ContactForm from

  • 0

Using django-contact-form, I have overridden the form class:

from contact_form.forms import ContactForm
from django.conf import settings

class ContactFormPublic(ContactForm):

    tuples = settings.WORKSHOP_ADMINS
    recipient_list = [mail_tuple[1] for mail_tuple in tuples]
    from_email = 'Joe Jones <joe@jones.org>'

That works, but I want the from_email to be that of the name and email submitted in the form itself. Tried referring to “self.email” in the form, but it complains that self is not defined. Seems like it should be simple, but I’m not able to tell from the documentation how to solve this.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T21:41:51+00:00Added an answer on May 23, 2026 at 9:41 pm

    Ok, I took a look at the ContactForm class. The easiest way I can see to set the from_email to the email submitted in the form is to override ContactForm.get_messge_dict:

    from contact_form.forms import ContactForm
    from django.conf import settings
    
    class ContactFormPublic(ContactForm):
    
        tuples = settings.WORKSHOP_ADMINS
        recipient_list = [mail_tuple[1] for mail_tuple in tuples]
    
        def get_message_dict(self):
            if not self.is_valid():
                raise ValueError("Message cannot be sent from invalid contact form")
            message_dict = {}
    
            """
            I removed 'from_email' from the message_part tuple check and updated the
            message_dict, setting the 'from_email' to the value of self.email
            """
            for message_part in ('message', 'recipient_list', 'subject'):
                attr = getattr(self, message_part)
                message_dict[message_part] = callable(attr) and attr() or attr
            message_dict.update({'from_email' : getattr(self, 'email')})
    
            return message_dict
    

    Hope that helps you out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well, I have one form, similar to dajax django forms example, all is working
I'm using Django Contact Form on a website to allow visitors to send emails.
Is it possible to have a variable number of fields using django forms? The
I'm having trouble getting django's django.contrib.localflavor.au.forms to validate my form input. I have tried
Am using django forms on my app. I have a model Client like this:
I have just started learning django. I created a form from django models. On
Using Django 1.1, I am trying to select the maximum value from a varchar
I just started using django for development. At the moment, I have the following
I am using django-userena . I have a model called UserProfile . I've added
I have a problem in customizing labels in a Django form This is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.