Clear input values - html

Data comes from a Servlet to HTML input field in a JSP page. When I press <input type="reset">, the data is not cleared. How can I solve this?

HTML reset buttons do not clear the fields in the form; they reset the fields back to their initial values (see example).
If you want to actually clear the data, you'll need to write a specific server-side controller to do that, or use javascript.

Related

Pre-Populate HTML form file input

I have a VBScript that goes over an HTML form, fills it with fixed values and then submit it. It works fine so far, but now i need to set the location of a file that is going to be uploaded within the form data.
I believed if I set the location on the value it was going to work, but it doesn't.
<input type='file' name="file_field" value='file_location'/>
Also, I found this while researching. It says...
input type=file
Value: Sets or retrieves the displayed value for the control object. This value is returned to the server when the control object is submitted.
Is there a way (by code) to fill that input, even with jQuery?
No. This is not possible.
Browsers block against setting the value attribute on input of file type for security reasons so that you can't upload a file without the user's selected any file himself.

How to write value to an input type = file of an form using php

I am able to write value to an input t form type= text
for ex
<input type="text" value="xyz">
But what i want is, to write a value to input type="file" . I have tried the code below but it's not working.
<input type="file" value="something">
You cannot, for fairly obvious security reasons.
If a webpage could specify a default value for a file input, then it could (for example) specify c:\place\where\finance\software\stores\accounts\by\default (and then use JavaScript to submit the form without the user having to do anything).
PHP aside, HTML doesn't let you assign values to input type="file" elements as a security measure. If HTML had this power, you could setup several of these fields and point each one to a windows file on the user's computer. The result would be a victim submitting a form with no idea they were also submitting sensitive information. No JavaScript is required. The victim might submit such a form to log in or post a comment on a blog somewhere. Why wouldn't the victim notice they are also submitting a file? CSS can style such elements offscreen using negative coordinates so its a lot like an input type="hidden", just in this case it would submitting a file instead.

POST more information from HTML page (more than input values)

I am starting web developement.
While POSTing a form, all the input fields are sent as properties (Content-Disposition). I would like to add more information (I mean more properties sent by POST), like a value of some html tag, or the value of an attribut of some div. Is this possible ?
Well an idea to resolve that is to use "hidden input" (#html.HiddenFor). That's what I am going to do waiting for better solution.
What server side technology are you using? You will likely use JavaScript to get other values from your form then submit, but it really just depends. You may want to be more specific.

"Protect" text box value from input (HTML form)

I was wondering whether it is possible to assign a value to an HTML text box and protect it.
What I mean is make it´s content unmodifiable, so that when the form gets submitted im "sure" it was this value which was submitted.
BTW I realize the easier way would be not to "listen" fot this input and just assign it but it would come in handy to be able to do what´s stated above.
I hope the question is clear enough, please ask for any needed clarification.
Thanks in advance!
EDIT: I was definitely not clear enough but I tried to express that i should hold the value after submitted (not modifiable in client side)
No, it's not. You should never trust user input, which includes form submissions.
The other answers tell you how to mark the field as read-only. This is useful if you want to display a particular value, while showing that it's not intended to edited.
However, it can still be modified with Firebug, DOM Inspector, etc. Or, they can just submit a HTTP request without using the browser at all.
I would recommend storing the value in a session instead.
Set the readonly property of the input element:
<input type="text" readonly="readonly" />
This will prevent any modification (except if the user edits with a DOM Inspector). Always validate input on the server. If you do not want any changes made, don't allow the user to edit it.
http://www.w3schools.com/tags/att_input_readonly.asp
Form inputs have a 'disabled' and 'readonly' attributes you can set to make them un-editable.
http://htmlhelp.com/reference/html40/forms/input.html
Though you can never be 100% sure what is getting sent from the client side. The entire DOM is editable by the client.
Just do this
<input type="text" value="VALUE" readonly />
Then itll be read only :)
<input type="text" readonly="readonly"/>. But: Never be sure, and validate data on the server side. It is very easy to request GET/POST with invalid data.

Ways to remove the autocomplete of an input box

I need a text input field which does not use the autocomplete function - If a user has submitted the form before, his previous submissions should -not- appear as he types into the form again, even if he is typing the same thing again. As far as I can tell, there are a few ways to do this:
1. <form autocomplete="off">
However, I believe this is a proprietary tag, and I am not sure how compatible it is across browsers
2. Give the input field a random 'name'
One could even use JS to set the name back to an expected value before submission. However, if the user does not have JS installed, you'd need another hidden input with the name - and the php code on the other side gets messy fast.
Do you know of any other ways? Is one of these ways the "accepted" way? Comments?
Thanks,
Mala
Lookie here: Is there a W3C valid way to disable autocomplete in a HTML form?
Stick with the random name. You can do it simply enough server and client and you meet your no-js requirement.
You can store the original and changed name in a $_SESSION variable before outputting the form, and after the user submits, just get the name from there:
$random_name = md5('original_name' . time());
$_SESSION['original_name'] = $random_name;
...output form...
And after submitting you can easily get the value from $_POST using the $_SESSION variable:
$field_value = $_POST[$_SESSION['original_name']];
Just be sure that you have sessions available by calling session_start() before any processing.
Autocomplete is something that browsers decided to do on their own, so there’s certainly no spec document to look at.