I have this form in my html code:
<form action="upload" id="upload-dropzone" class="dropzone">
<input type="hidden" name="browser-path" id="browser-path" value="/">
<div class="browser-buttons rrtl">
<a id="browser-btn-upload">Upload</a>
</div>
<div class="lltr" id="browser-path-view"></div>
</form>
<script type="application/javascript">
Dropzone.options.uploadDropzone = {
clickable: "#browser-btn-upload",
};
loadBrowserContent();
</script>
As this document said, the hidden input field browser-path will automatically be submitted as POST data to server.
I have this code in my server side:
System.out.println(request.getParameter("browser-path"));
But this code always prints null to output!
How can I submit this hidden field to my server and how can I read it?
Edit:
Thanks to steeno, the form enctype is multipart/form-data so I have to read the fields from another way.
I assume you use Java as backend language?
As mentioned in the following question: HttpServletRequest get JSON POST data
the problem yould be the encoding of the post request. Maybe try to get the post data with getReader instead of getParameter.
Related
So i made this script below so that someone can enter an order ID and it would redirect to the following http://domain.tld/order/254441.
but it give me a query-string of ?webid=254441 at the end the URL. How do I remove this?
function urlRedirect(){
var action_src = "/orders/" + document.getElementsByName("webid")[0].value;
var form_url = document.getElementById('form_url');
form_url.action = action_src ;
}
<p>Search by ID</p>
<form id="form_url" onsubmit="urlRedirect()"><input name="webid" type="text" /> <input type="submit" value="Search" /></form>
And if anyone has suggestions on making the code better that would be great! :)
Thanks.
Change the method of your form to "POST".
<form id="form_url" onsubmit="urlRedirect()" method="POST">
HTTP POST requests supply additional data from the client (browser) to the server in the message body. In contrast, GET requests include all required data in the URL. When the method is GET, all form data is encoded into the URL, appended to the action URL as query string parameters. With POST, form data appears within the message body of the HTTP request.
See the documentation.
I have an input field:
<input type="file" id="inputID" name="file">
When a button is clicked to submit, a JavaScript function will run (url: upload.php). I need to be able to access $_FILES["inputID"]["tmp_name"] from this input field so that I could use it on upload.php as,
move_uploaded_file($_FILES["inputID"]["tmp_name"], $target_file)
Is this possible?
At the moment, I get an error:
Notice: Undefined index: inputID
Any help would be very much appreciated.
Thanks so much! :-)
move_uploaded_file() is a php function, running on a PHP-based server-side application.
It is handled by PHP when your form has been submitted.
You cannot access it from JavaScript before it has been sent, whatever would be the way you would submit it, both asynchronously with an XHR Request, or directly submitting the form to its handler route.
you can access it after it is submitted, although I don't see why you should:
<?php
...
$tmpname=$_FILES["file"]["tmp_name"]
...
?>
...
<script>
var tmpname = <?=$tmpname?>
...
</script>
...
I'm not clear on what you are trying to do. If you want some ajax upload functionality It's better to use a js library.
I am new to spring web applications. When I submit a form, the request mapping is getting a "dual" parameter.
My form is set as:
<form action="" method="post" name="myform">
......
</form>
I use a javascript to submit the form, for example, when I submit the form for going to various pages, my javascript is like this:
function gotoPage(pageNumber)
{
document.forms['myform'].action="trx?page=" + pageNumber;
document.forms['myform'].submit();
}
So when I have a link like this on my jsp page,
Page number: 3
On my controller for the request mapping for /trx, I should be getting parameter page as value "3", but I am getting value as "3,3".
Any ideas why? I noticed only on the page parameter, If I use parameters like action=search or action=sort. It all works out fine.
Dumb question. :)
Had a <select name="page"> in the form.
I have a form on a website that is not directly selectable (as it is embedded in a javascript). So selecting it via mechanize browser object is not possible. What i want to do is to create a form just like that one and submit it using the browser object.
The form is
<form method="POST" action="Action.php?action=338&n=66&t=mine">
<input id="Mine66" type="hidden" value="22" name="duree">
<button class="boutonsGeneral" value="submit" type="submit" name="travail">
<span class="infoBoutonsGeneral" title="">
Work
<span id="dureeMine66" class="boutonsGeneral_duree boutonsGeneral_dureePlus">22 hours</span>
</button>
</form>
I used firebug and here is the info. The URL posted to is http://www.renaissancekingdoms.com/Action.php?action=338&n=66&t=mine
Parameters
duree 22
travail submit
Request Headers From Upload Stream
Content-Length: 23
Content-Type: application/x-www-form-urlencoded
What i have done so far is that i managed to log into the site and did the following
form = mechanize.HTMLForm('http://www.renaissancekingdoms.com/Action.php?action=338&n=66&t=mine', method='POST')
form.new_control('duree', 'hidden', {
'id' : 'Mine66',
'value' : '22'})
form.fixup()
br.form = form
br.submit()
But this doesn't seem to work. Any ideas where i am going wrong?
have you tried going directly to the link passing the post data as a parameter? like this :
r = opener.open('http://example.com/', data)
where data is the post data as a dictionnary
I create a form with some inputs and other information on a client by JSP,then i want to send the form to the server while a servlet runs on the server. My question is how to save the entire form which I post inside a html file, the html file will be created once I get the request.
<form name="myform" action="servlet on server" method="post">
<input type="button" id="sth" />
....
</form>
I want to use the File class to create the new html file, but how can I get the entire form and write it in the new file?Thanks.
I guess you could do some javascript to send a post request with a field containting the inside html of your document of your browser.
<script type="text/javascript">
myform.sth = document.innerHTML;
myform.submit();
</script>
I cannot give you the exact syntax, but that's the idea.
BUT it surely is a weird design you are building