Iamcool
Iamcool

Reputation: 1445

How to clear form submission data

I have a form submission in a page done with POST request. There is no separate page for form itself.

When a user submits form and refreshes the page, the form data in the browser is not getting clear and thus asks "Confirm form submission" using an dialog box.

How to remove this?

I am using django for form submission and currently not using any Async submission (JavaScript) here.

Upvotes: 0

Views: 1049

Answers (2)

Nilesh
Nilesh

Reputation: 2555

if request.method == "POST":
    if form.is_valid():
        ...
        ...
        form = ABCForm()
        return render_to_response(request, context={'form':form}, RequestContext)

Here ABCForm is your django form name which you are passing in context for displaying in django template

Upvotes: 0

kanu
kanu

Reputation: 726

I think its cleaner to redirect to the same page after the form is complete. This way you use a fresh GET request without any problems when reloading the url.

if method.POST:
    ...
    if form.is_valid():
        ...
        return HttpResponseRedirect(request.path)

Upvotes: 1

Related Questions