Cancel form file upload submission - django

I work on a file upload form with some additional data and want to have a cancel button.
My site is running on Django. I submit the form over the normal way with a submit button without Ajax but I show a progress bar of the upload with jQuery so I enter the submit event with jQuery to show the progress.
Is there a way to cancel this submission with jQuery or some other solution?
I solved this questions here:
How I can call the browser escape (esc) function
Thanks

As Far as i know Once, the Submit has reached the server there is nothing much you can do with it (the form).

Related

Django admin forms error, delete form with errors and then press cancel

I am using Django 1.11.2.
In every form in admin(on edit), if I have errors on the form, and I press delete, and on the delete page I press cancel to go back, I receive this error:
Confirm Form Resubmission
This webpage requires data that you entered earlier in order to be properly displayed. You can send this data again, but by doing so you will repeat any action this page previously performed.
Press the reload button to resubmit the data needed to load the page.
ERR_CACHE_MISS
If The form is clean and I don't have errors on it, is working.
How can I resolve this?
If I understand correctly, this is browser related : when you go back on a page where you submitted a form, the browser has the POST/GET values in its cache and asks you if you want to resubmit with the cached data.
You can only resubmit the data, you can't see the form as it was like that. You have to directly go to the URL (usually F6+Enter)

Stopping multiple view calls generated via frenzied button clicks (Django app)

I'm uploading an image file in a basic Django web app. There's an upload button in the html template wrapped around by a form tag. Once the upload button is pressed, the underlying view takes over and processes image upload.
In the Chrome browser of my colleague's Macbook, pressing upload multiple times really quickly manages to call the underlying function multiples times too. I end up getting a plethora of copies of the image being uploaded.
However, this isn't replicatable in my own environment's Firefox (Ubuntu OS). Seems this issue is browser sensitive?
In any case, how do I cut off this code behavior? If the user goes into a click frenzy, I don't want multiple images to go up. Can someone guide me how to handle this in Django? I would prefer a non-JS, server solution too.
Note: Let me know if you need to see my related code.
Many people faces this issue. If the submit button called 3 times wihtout waiting to refresh the browser, it will gonna add 3 times.To prevent that you can use jQuery.
For example on form submit you can show the loader or disable the submit button,
$('#login_form').submit(function() {
$('#gif').css('visibility', 'visible');
or
$('#button').prop('disabled', true);
});
Edit for server side implementation:
I do not suggest this for user interface point of view but if you can also valid submits using sessions or cookies.Generate random token in your view and set this in your form as hidden input.
for e.g.,
def checkform(request):
form = ExampleForm(request.POST or None)
randomtoken = #generate random token here and set in session or cookie
if form.is_valid():
# check_token here
session_value == request.POST.get('your_hidden_token')
# if matched than change the random token and save your data else do your restriction processing
render ( request,'template.html',context={ 'form':form,'randomstring':randomstring } )

Page reload after form submit using WFFM Sitecore8

I have created one form using WFFM, and a sending mail on tap of submit button,
After click on submit button it display message "Thank you for filling in the form" and textbox is hidden after submission the form. and when I refresh website it ask me to repeat action.
How can I hide the form after submission?
Changing the Success Mode field to Redirect would certainly be a good workaround to your problem. A dedicated thank you page has the added benefit of being easier to goal track with 3rd party analytics tools like Google Analytics.

django login popup

I've been trying to figure out how to do a modal login in django and have been having some trouble. Is this possible? It seems like it should be. I imagine the solution involves writing a view that takes a POST request and returns some JSON.
Are there any examples out there of how to do this in a clean way?
The easiest way I've found is to do the following:
Write a simple standalone login view
Display this view on your pages as an iframe using a javascript modal dialog (I recommend Colorbox).
Because you're displaying an iframe, you don't have to worry about ajax sends etc. The iframe can just post data and redirect normally.
On a successful login, redirect the iframe to a 'success' page. After a few seconds, have that page send a message to the parent window, which can then close the modal box and make any necessary changes to itself.

Process a query without changing the page

We have a page which is dynamically generated after a few queries in the database. There are some links that when they are clicked by the user, update some information on the database but they change nothing on the webpage (or the display a discrete message).
How could we stay on the same page without re-rendering it?
Ideally, the corresponding view.py would process the queries and update the database but not the webpage.
You can send and receive your own XMLHttpRequest, but it is too much of works to do and IE will create a lot of problems.
Have you ever heard about jQuery? I strongly recommend you take a look at it and learn how to send and receive Ajax request using it.
You need to make an AJAX call back to the server with the user's actions, and process it on the server. You probably want a different view to process the AJAX request -- you could do it with the same view, but it would be somewhat silly to. The response from that view contains data (probably as JSON) or HTML, which you display on the page with javascript. Check out jquery -- it's great for the client side.
You could accomplish this with plain Javascript and AJAX. When the user clicks on a link, use XMLHttpRequest to call view.py to process the queries.
eg. For the link: <a href="#" onclick=submitdb(); >Click me!</a>
For a tutorial on implementing AJAX (XMLHttpRequest) with Javascript, have a look here:
http://www.quirksmode.org/js/xmlhttp.html