Hi Daniel,

Thanks for your solution. It worked.

Thanks,

Karthik

On Sep 18, 1:46 pm, Daniel Roseman <[EMAIL PROTECTED]>
wrote:
> On Sep 18, 9:34 pm, Karthik Krishnan <[EMAIL PROTECTED]> wrote:
>
> > 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:
> > <snip>
> > 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})
>
> <snip>
>
> > Is there anything I am doing wrong?
>
> Just one tiny thing. In the else clause, you have this:
>     form = EditSiteForm(initial_data)
> As you have found, this triggers validation.
>
> What you want instead is this:
>     form = EditSiteForm(initial=initial_data)
> This lets the form know that the data is not to be validated, just
> displayed.
>
> See 
> here:http://docs.djangoproject.com/en/dev/ref/forms/fields/#dynamic-initia...
> --
> DR.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to