Using POST in an HTML form - html

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.

Related

HTML input form to external link

I am working on a new project and decided to do a lot of the coding myself, I am by no means a web developer but here we are :)
So....
I am coming towards the end of coding and just linking a few things up, I have WHMCS running on a vhost based external link and I need my domain search form to direct people from my main website to the vhost external link.
Here is the code I have so far...
<form method="post" action="https://bill.spacesrv.com/cart.php?a=add&domain=register&" target="_blank" class="uk-form idz-search-domain-form">
<fieldset>
<input type="text" class="uk-form-large uk-width-1-1" name="query" value="" placeholder="find your perfect domain name">
<button type="submit" class="uk-button-large idz-button blue uppercase">Find Domain</button>
</fieldset>
</form>
I have the domain in the action tag, I need that to stay the same and what the customer will search in the search box needs to go on the end of the domain.
This is what the final link should look like...
https://bill.spacesrv.com/cart.php?a=add&domain=register&query=domain.com
But currently when I hit the search button it is going to this link...
https://bill.spacesrv.com/cart.php?a=add&domain=register&
It is not adding the query={searched domain} to the end of the link.
It is a WHMCS link which is open for the world to see anyway, its not a link that needs to be hidden.
Nothwithstanding the fact that you need to take care of security ( dont open the target page for forms coming from anywhere ), you just need to specify the GET method for the form :
<form method="get" action="https://my.page.com?a=add" target="_blank" class="uk-form idz-search-domain-form">

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.

How to open another URL in a different window when a html page is loaded?

I have one html page, with a form on it. When the user posts the form, I want the form receiving the response to automatically open up the URL passed by the post in a new browser window.
Basically the URL is passed to the the other page, which in turn opens the URL in a new window then displays another form.
Thanks in advance.
Cheers
Shane
Add target="_blank" attribute to the <form>.
<form action="http://google.com/search" target="_blank">
<input type="text" name="q" />
<input type="submit" />
</form>
This will show the response in a new (blank) window. Note that this happens before the HTML page is loaded (it wouldn't make much sense otherwise).

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.

How do I submit an HTML form to a Popup windows with resize disabled?

I had designed an HTML form with submit button. But instead of submit it to another page I want to submit to pop up windows where I can limit the size of the pop up windows say "320x240" hide all the toolbar, disable resize.
Here's my go at it; this JavaScript snippet should go into the head of your page:
<script>
process = function()
{
window.open('about:blank', 'popup', 'width=320,height=240,resizeable=no');
document.login.setAttribute('target', 'popup');
document.login.setAttribute('onsubmit', '');
document.login.submit();
};
</script>
And this is a sample form for demonstration purposes:
<form action="handle.html" method="get" name="login" onsubmit="process(); return false;">
Username: <input type="text" name="username" id="username" /><br />
<input type="submit" />
</form>
Now, here's what's happening: first, we set up a form and give it an onsubmit attribute that tells it to run the function process() and return false; instead of submitting normally; from this point, that function takes over and creates a popup window, giving it a name, and some features (by all means, add any surplus ones you'd like), and then attention comes back to the form, where we now set the target attribute to the name of the window we just created.
We then have to clear that onsubmit that we set earlier, or this same exact thing will happen again, and that's certainly not what you want. Finally, we just have the form submitted again and it now passes all of its information to the popped window; from there, it's just getting handle.html (or whatever you end up calling your processing page) to do its work with the data.
Hope I've helped.