keeping value of file input field if an error

Joined
12 Feb 2006
Posts
17,674
Location
Surrey
currently i have a form which checks errors such as no name first, then if none it'll deal with the file uploading.

one downside (though perhaps it's not related to how i'd done the checking) is if there is an error with the form, the input field for the uploading of the file goes blank and needs to be selected again. is it possible to have it so this is filled in automatically even if there is an error?
 
What language are you using? If PHP you could use the session object, or if .Net look at the session or viewstate depending on the scope you want the variable to have.

You could also use JavaScript on the front end to check the form before it's submitted - check out jQuery validate
 
i'm using php. i prefer to get it working perfectly without jquery and then add jquery to improve so not an option yet.

why can't i fill out the field by setting the value as $_POST['uploadedfilelocation']?
 
As long as the form uses POST, and your input box's name is right, then $_POST['Name'] will post the selected value, and then you just use value='<?php echo($_POST['Name']) ?>'

If it's not working, it's not POST'ing correctly. But if you're error checking it then presumably it is? Echo the POST variable at the start of the page to make sure it's working.
 
try setting the variable

Code:
<?php $uploadedfilelocation = $_POST['uploadedfilelocation']; ?>

<input type='input' value='<?php echo $uploadedfilelocation ?>' />


You should be cleaning stuff from $_POST anyways ;)

Not that important in this case though, is it? Genuine question, dev'ing a site at the moment and would like to know :).
 
It won't make any difference for this particular circumstance no, but it is tidier and much easier to work with normal variables over POST formatted ones!
 
ok this is odd then as nothing is working.

this is what i have with small changes for this forum...

Code:
<input type='file' name='cv' id='cv' class='wide' value='<?= $cv; ?>'/>

if i change value to anything, e.g. $_POST['cv'], or "123ssdfoi" nothing is being shown, and also echoing $_POST['cv'] at start of file gives nothing.
 
Back
Top Bottom