This question already has answers here:
How to set a value to a file input in HTML?
(10 answers)
Closed 6 years ago.
Note:
The answers & comments below reflect the state of legacy browsers in 2009. Now you can actually set the value of the file input element dynamically/programatically using JavaScript in 2017.
See the answer in this question for details as well as a demo:How to set file input value programatically (i.e.: when drag-dropping files)?
In HTML we can set the value of a textfield by writing :
<input type="text" name="doc_intitule" maxlength="100" size="24" value="<?php echo $ret['doc_intitule']; ?>">
But how to set the value of a file field ?
Please refer to this
How to keep input type=file field value after failed validation in ASP.NET MVC?
As far as I am aware of, you are not meant to pre-set file field values for security purposes.
You cant set value of file field by any means.
See here: info
You can't set a default value to a file field.
This is a security thing: you can just make a form submit by code, so you would be able to force a user to upload a file without their knowledge.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 months ago.
This post was edited and submitted for review 8 months ago and failed to reopen the post:
Needs details or clarity Add details and clarify the problem by editing this post.
Improve this question
In my web application, I am trying to add a "Edit button" option to enable a user to change his information which he has already submitted. "Edit button" trigger a Modal with edit form which is pre-filled with values from Mysql database (provided by user at the time of registration).
But complete value of variables is not coming in input fields.
For example: Originally user filled his name as Asheesh Kumar which is saved in the database but edit form input field shows only first word of the name "Asheesh".
HTML code below:
<div class="col-md-4 ">
<input type="text" class="form-control" id="name" name="name" value=<?php echo $Name; ?>>
</div>
What I am getting in Input field:
screenshot of output
its happening for all Input fields in Edit form.
Well.. hard to tell without any code. But, I would start checking the following:
The variable is really coming complete from the database?
The html input does have a maxlength attribute?
If you're using javascript to set the input value, are you escaping the especial characters to avoid any javascript error?
Update
After the update in question (that was missing the code), I could notice that the problem is because you're not opening and closing the quotes of the value atribute of your input field.
You should change this:
<input ... value=<?php echo $Name; ?>>
To this: (note the closing " of the value attribute)
<input ... value="<?php echo $Name; ?>">
Only two possible error you have made.
Most probably your MySQL Type Length
As for the HTML Input Field, instead of using input use Text Area when you call out value from database.
This question already has an answer here:
How to set file input value when dropping file on page? [duplicate]
(1 answer)
Closed 2 years ago.
I was using PHP for updating data in Mysql and when I open the update link then if I don't input anything in the file input type then after clicking on the submit button the previously present file/image is not sent.image of update link
But when I input something in input file box in update page then image is uploaded.
Short answer: no.
Longer version: theres no way for you to set a default value for a file-selection. because a file-input points to a file on the local computer (if one was selected). it would be a great security issue if a web dev could f.e. say "make the local passwords file the default value".
you have to handle this another way - default value is not an option for file inputs :)
best,
stefan
This question already has answers here:
Does form data still transfer if the input tag has no name?
(3 answers)
Closed 9 years ago.
I read $_POST is empty after form submission topic and I wondered how to get the data from input without attribute name?
<input type="text" >
var_dump($_REQUEST)//empty
var_dump(file_get_contents('php://input')) //empty
Basically, the form should be specified its name. If not, you cannot get it from the server-side.
However, the form without name is also valid in HTML5. The reason is that you might sometimes want to use for form submission via AJAX or Javascript app. In many cases
This question already has answers here:
Can you re-populate file inputs after failed form submission with PHP or JavaScript?
(2 answers)
Closed 10 years ago.
I have a HTML file field <input name="File" id="FileName" type="file"/>. When I submit the form, I do receive the file, all fine. However, when I validate the user's input and cannot accept the values provided, I will need another round trip. As usual, I will redisplay the form plus error messages.
For text field or textarea I can set the (already) provided value, e.g. by value or just echo the value in the textarea. How could I do the same for file fields? I want to avoid that the user always has to reselect the file in the browser.
-- added --
Comments below are right - there are workarounds described in the mentioned SO questions:
PHP remember file field contents
Can you re-populate file inputs after failed form submission with PHP or JavaScript?
Restoring the value of a input type=file after failed validation
This is not possible - you have to store the file on the server to do this. Then you can show the user a short info about the already stored file and the option to upload a new file or delete the file
This question already has answers here:
Keep values selected after form submission
(12 answers)
Closed 3 years ago.
I am trying to find what the easiest way to keep form values after post. I am really trying to have to keep from learning ajax right this second for the one form, Plus I am not sure how hard it would be to implement ajax into my already existing google map page. So I am trying to find a way to retain the values of two date fields after submit has been pushed
If you are looking to just repopulate the fields with the values that were posted in them, then just echo the post value back into the field, like so:
<input type="text" name="myField1" value="<?php echo isset($_POST['myField1']) ? $_POST['myField1'] : '' ?>" />
you can save them into a $_SESSION variable and then when the user calls that page again populate all the inputs with their respective session variables.