Hi, I have a form which contains some prefilled data and some to be filled in by the user. I have no trouble getting the forms to be prefilled. What I want is thatfor a GET request, if the form data pre exists, then display it; if not, then show a blank text field . For a post request, if the field is required and is not filled, then show the error message. What I am getting is this that, when I call the url ,
I automatically get a validation failure error message. My code is as follows: class EditSiteForm(forms.Form): site_type = forms.ChoiceField(label = 'Type', error_messages = {'required':'Please enter type'}, choices = SITE_TYPE_CHOICES); name = forms.CharField( max_length = 64, label = 'Name Of Site', error_messages = { 'max_length' : 'The maximum permissible length is 64.'}) street = forms.CharField( max_length = 64, label = 'Street', error_messages = { 'max_length' : 'The maximum permissible length is 64.'}) number = forms.IntegerField(label = 'Number', error_messages = { 'max_value' : 'The maximum permissible length is 16.'}, min_value = 0, max_value = 9999999999999999) postal_code = forms.CharField(max_length = 16, label = 'Postal Code', error_messages = { 'max_length' : 'The maximum permissible length is 16.'}) In my views.py if request.method == 'POST': form = EditSiteForm(request.POST) if form.is_valid(): # Get Cleaned data. type = form.cleaned_data['type'] name = form.cleaned_data['name'] street = form.cleaned_data['street'] number = form.cleaned_data['number'] postal_code = form.cleaned_data['postal_code'] else: # Get Request. Bind the EditSiteForm to the request. # Setting up initial data. initial_data = {'site_type' : site.site_type, 'name' : site.name_address, 'street' : site.street, 'number' : site.number, 'postal_code' : site.postal_code} form = EditSiteForm(initial_data) return render_to_response('edit_site.html', {'site' : site, 'form' : form}) My html page. <!-- The form action is the current url. --> <form action="{{site.network_id}}/edit/" method="post"> {{form.as_p}} <input type = "submit" value = "submit" > Is there anything I am doing wrong? </form> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---