Adding Submit button on the second page did not work - html

I am working on a demo project that uploads a photo and returns with the name of the person. So basically I use HTML and it consists of 2 pages, the first page - for users to upload photos and submit it while the second page - the recognized name in the photo will be shown. I have a web service that I need to enable it for face recognition to work. The first page has a submit button, which is to upload the photo, but I wanted the submit button to be on the second page as well so that the users can submit another photo, without the need to go back to the first page. I copied the HTML code in the first page to second page,
<form>
<div class="upload-btn-wrapper">
<button class="btn">Submit</button>
</div>
</form>
the structure of the submit button is there. But it doesn't work, while it worked for the first page, it did not work on the second page. What could be the problem? Let me know if u need more clarification I would be happy to do so
The Code for the first page
Page 1
The Code for the second page
Page 2
The codes for both pages are almost the same.

You need to add condition when you are submitting and action attribute as well where you want to submit.
<form action="upload.php">
<input type="file" name="file" id="uploadFile" />
<div class="upload-btn-wrapper">
<button type="submit" class="btn">Submit</button>
</div>
</form>
for validation, you need to add some jquery code
$(document).on("click", ":submit", function (e) {
if( document.getElementById("uploadFile").files.length == 0 ){
alert("no files selected"); // or you can use other approach
e.preventDefault();
}
}

Related

Keep on same page after submit POST through form

I've a little problem. I submit a form to my route/uploadpdf with
<form action="http://localhost:3000/user/uploadpdf" enctype="multipart/form-data" method="post" onSubmit=window.location.replace('http://localhost:3000/statictoken')>
<input type="file" name="upload" multiple>
<input type="submit" value="Upload">
</form>
and when it is complete the browser tries to traverse to uploadpdf.
What I actually want is to stay on the current page ("statictoken") and refresh. You can see I've attempted to replace onSubmit, but it doesn't work.
The form action attribute is used to send the request to the specified page. If you want to send the request to the current page itself, you should have the following :
<form action="/" ...>
But keep in mind that now, you have to tackle the functionality of uploadpdf page on your 'statictoken' page.
You can also redirect to the "statictoken" page from the "uploadpdf" page after the file upload completes.
Or better, you can use Ajax File Upload, so that form is submitted asynchronously without redirecting you to the "uploadpdf" page.

MechanicalSoup 2 submit buttons in form, provide time for the first to exert its effect or not?

The online HTML-form I want to fill out using MechanicalSoup has 2 submit buttons (so 1 form with 2 submit buttons). The first button (red in the picture "Toevoegen") is to upload a photo after choosing a file. The second button (not shown) submits the completed form. I have figured out how to address the different buttons using the form.choose_submit() function, so that's fine.
My question now is the following:
When I fill the form by hand, I noticed that after selecting the file and pressing the first (red) button, it takes some time (1-2 secs) for the file to upload. When I now fill out the form using mechanical soup, do I have to include this time (1-2 secs) for the photo to upload (for example using the time.sleep()) before I (make MechanicalSoup) fill out the rest of the form and submit it using the second submit button? Or will the form figure out that it has to upload the pic first and wait for that before executing the final submit order? So it's really a timing issue I have to coordinate the proper functioning of both buttons...
I hope this edit clarifies things a bit more.
Thanks for any suggestions!!
If it helps: this is what I found in the HTML form for the first submit button:
<div id="edit-submitted-file_add-ajax-wrapper">
<div class="form-item webform-component webform-component-file webform-component--file_add">
<label for="edit-submitted-file_add-upload">Add File</label>
<div class="form-managed-file">
<input type="file" id="edit-submitted-file_add-upload" name="files[submitted_file_add]" size="22" class="form-file" />
<input class="button form-submit" type="submit" id="edit-submitted-file_add-upload-button" name="submitted_file_add_upload_button" value="Toevoegen" />
<input type="hidden" name="submitted[file_add][fid]" value="0" />
</div>
</div>
</div>
When submitting a file, the file upload is part of the form submission. There's no point waiting before submitting, because this is not when the file upload happens. Unless the website is seriously broken, there's no point waiting after either, because the .sumbit() method call is blocking, i.e. it returns only after the form submission, hence the file upload, is completed.
However, it's hard to tell what you should do exactly in your case: it seems the first submission is done without reloading the page, hence using JavaScript. MechanicalSoup does not do JavaScript, so it may or may not work (in a perfect world, sites that work through JavaScript have a non-JavaScript fallback, but ...).
Probably the best for you is to try and see what works.

Simple indication that file is uploading after pressing Submit

I'm looking for a simple way to show that a file is being uploaded after the Submit button is pressed. The files can be up to 50 MB in size and users can think the browser has frozen because it takes a long time. I'm not looking for anything animated, just something like the word Loading... that appears next to (or in place of) the submit button. An onclick might do it but I'm not sure if it would interfere with the submit process.
Display a "spinning gif" right next to the submit button which is made visible on the onSubmit event. Redirect your form to a new page or reload current page when form is done uploading.
Here's a very simple example:
<script>
$(".spinner").hide();
function loadSpinner() {
$(".spinner").show();
//do validations
//redirect
}
</script>
The form could look something like this:
< form onsubmit="loadSpinner()">
.
.
.
<div>
<input id="submitButton" type="submit" />
<span class="spinner"><img src="images/loading.gif" /></span>
</div>
</form>
This example assumes you're using jQuery.

Using POST in an HTML form

I am using POST in an HTML form to POST large number of arguments.
I wrote something like this:
<form action="get_status_aisleid.html" method="POST">
<input type="hidden" name="aisleId" value=<% $aisle_id %> />
<input type="hidden" name="enter code heretype" value="verified" />
<input type="hidden" name="value" value=<% $values[1]%> />
<a href="#" onclick="this.parentNode.submit()">
<% $verifiedbaySize %>
</a>
</form>
Everything works fine, if I click on a link in the same window.
But if I right click and open it in a new tab, then my new file (which is doing some operations on arguments passed and then downloading a file) is not called. Instead, the same page is refreshed.
Can someone please suggest something?
Right clicking an opening in a new window will always follow the link (i.e. href="#" meaning "Go to the top of the page". The JavaScript won't run.
No built in control of the browser will submit a form while giving the user the option to choose if it should be in the same or a new window.
This isn't normally a useful choice anyway - opening in a new window is something usually done when the user intends to return to the current page to pick up where they left off, and a form is not something normally presented in the middle of another task.
The closet you could come would be to add a second JavaScript triggered control that sets the target attribute of the form to _blank before triggering submission.

Forms in html - How do I make the form do 2 things?

I have a form to sign up to getting a rss feed through Feedburner.
this is the code -
<form action="http://feedburner.google.com/fb/a/mailverify" method="post">
<p><input name="email" type="text" /></p>
<input name="uri" type="hidden" value="dafyomi" /><input name="loc" type="hidden" value="en_US" /><input type="submit" value="click here to send" /></form>
<p> </p>
I want it to also sent the form data to a new window, and also change the window the user is on now - to a thank you page on the site.
Any ideas?
Thanks!
In clean HTML — impossible.
You can use JavaScript for this but it's ugly, breaks usability and probably most browsers will block it thinking you're trying to show an advertisement.
And as forcing opening a new window/tab/whatever is getting deprecated too, some browser may even ignore your ‘new window’ and try to open the thing in current tab. This would lead to undefined behavior of it trying to open two things in same window.
You may think about using one target page and <object/> or frames to display another if that's important. But that's not very usable too.
PS. And in all cases, the form can be submitted only to one of the pages. The second one will be plain GET.
I would like to suggest to use jQuery Ajax Form Plugins for this case. You can done two actions with one form submit by this way...
$('form').submit(function() {
$(this).ajaxSubmit({
url: myurl, //ajax request to myurl
success: function() {
return true; //submit form
}
});
return false;
});
I would add the "Thank you!"-phrase to the results page - after all, it can only be a line or two long, right?
If you feel that is not an option, you might want to do the something like this instead:
Form submits to server, and relevant data required to view the results page are saved in a Session
Redirect to Thank You-page, with a link to the results page.
Link triggers GET-request for the results page, and the results can be shown thanks to the Session variable.
If the page should only be available once, abandon the session.