file validation, preserving the file location

68 views Asked by At

I'm trying to create a full validation page for an input (sql insert) form.

What I've typically been doing are the following to preserve the values already input on the page in case one piece of validation fails (in which case the user is returned to the form to correct it with an error shown).

 echo 'value=" ';
 if(isset($_POST['NewGameName'])){ 
     echo $_POST['NewGameName']; 
 } // for text-fields
 echo '<option value="'.$i.'" ';

 if(isset($_POST['Score'])){ 
     if($i == $_POST['Score']){
         echo'selected="selected"';
     }
 }

 echo '>'.$i.'</option>'; // for dropdowns

But I can't seem to find a way to preserve the file location if the page is refreshed. Is there a way to do this? I've read that it's always cleared for security reasons which would be annoying but if it's the standard I guess people are used to it.

2

There are 2 answers

0
nl-x On

I think you have 2 options.

  1. is to use Ajax for validation. This way you don't leave the form with the filepath.

  2. Use javascript after the validation to go back in history history.go(-1) to the previous screen. I think when using history, the form entries are preserved.

1
Farzoqe Khan On

you could create a hidden field to store the file name and change the name through javascript by using onchange event on the actual file field. as soon as file name changes you could update the hidden field value. you get the hidden field value in the post variable and use this variable to refresh the value of the file field