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

  • SEARCH
  • Home
  • 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 8236643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:11:55+00:00 2026-06-07T19:11:55+00:00

I would like to create a form and the validation_forms that would check if

  • 0

I would like to create a form and the validation_forms that would check if some text apears in a box if another box has been checked correctly,

class Contact_form(forms.Form):

def __init__(self):

    TYPE_CHOICE = (
    ('C', ('Client')),
    ('F', ('Facture')),
    ('V', ('Visite'))
    )

    self.file_type = forms.ChoiceField(choices = TYPE_CHOICE, widget=forms.RadioSelect)
    self.file_name = forms.CharField(max_length=200)
    self.file_cols = forms.CharField(max_length=200, widget=forms.Textarea)
    self.file_date = forms.DateField()
    self.file_sep = forms.CharField(max_length=5, initial=';')
    self.file_header = forms.CharField(max_length=200, initial='0')

    def __unicode__(self):
    return self.name

    # Check if file_cols is correctly filled
    def clean_cols(self):
        #cleaned_data = super(Contact_form, self).clean() # Error apears here
    cleaned_file_type = self.cleaned_data.get(file_type)
    cleaned_file_cols = self.cleaned_data.get(file_cols)

    if cleaned_file_type == 'C':
        if 'client' not in cleaned_file_cols:
            raise forms.ValidationError("Mandatory fields aren't in collumn descriptor.")
    if cleaned_file_type == 'F':
        mandatory_field = ('fact', 'caht', 'fact_dat')
        for mf in mandatory_field:
            if mf not in cleaned_file_cols:
                raise forms.ValidationError("Mandatory fields aren't in collumn descriptor.")

def contact(request):

contact_form = Contact_form()
contact_form.clean_cols()
return render_to_response('contact.html', {'contact_form' : contact_form})

Infortunatly, django keeps saying me that he doesn’t reconize cleaned_data. I know i’ve missed something about the doc or something but i cannot get the point on what. Please help !

  • 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-06-07T19:11:57+00:00Added an answer on June 7, 2026 at 7:11 pm

    When validating an individual field, your clean method should have a name of the form

    clean_<name of field>
    

    for example clean_file_col. Then it will be called automatically when you do form.is_valid() in your view.

    Naming your method clean_cols suggests that you have a field named cols, which could cause confusion.

    In this case, your validation relies on other fields, so you should rename your clean_col method to simply clean. That way it will be called automatically when you do form.is_valid() in your view.

    def clean(self):
        cleaned_data = super(Contact_form, self).clean()
        cleaned_file_type = self.cleaned_data.get(file_type)
        # ...
    

    Finally, in your view, you have not bound your form to any data,

    contact_form = Contact_form()
    

    so contact_form.is_valid() will always return False. You need to bind your form to the post data with form = ContactForm(request.POST). See the Django docs for using a form in a view for a full example and explanation.

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

Sidebar

Related Questions

I would like to create a data entry form in Drupal 7 that is
I would like to create a form where a user can enter an arbitrary
I would like to create an order form for my ASP.net page (I included
I would like to create a c++ type that mimic the build-in type exactly.
I would like to create a class that runs something (a runnable) at regular
I am creating some text boxes at runtime and I would like to change
i would like create a array of structure which have a dynamic array :
I would like to create this shape using just css. I am pretty sure
I would like to create a json object to send as a post array,
I would like to create set of strings and below is the only limitation.

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.