1

I have a huge form that lets users (along with a lot of other inputs) upload multiple images, like this:

<input type="file" id="product_images" class="hidden" name="upload[]" multiple>
<input type="file" id="product_images_2" class="hidden" name="upload[]" multiple>
... 

Now, when there is an error in a certain input (e.g. String for "description"-field too short), the page reloads. After this reload I need to keep all the posted data in all the inputs. For a text input I know how to do it, like this:

<input name="name" type="text" value="<?php echo $_POST['name']; ?>"/>

but, how can I achieve this for the file inputs? I tried something like this:

<input type="file" id="product_images" name="upload[]" multiple value="<?php print($_POST['upload']); ?>">

Did not work though. Any ideas? Thanks!

Frank
  • 614
  • 1
  • 8
  • 31

3 Answers3

1

Maybe that's because you are validating in server, try to validate your field in browser, if the server reloads it will loose all your data saved in fields.

Try this validator personally i like it: http://jqueryvalidation.org/

Hop it helps

CaRRaSKo
  • 19
  • 2
  • But what if user disable javascript in his browser? Then there would be no validation at all. – Whirlwind Jan 23 '15 at 12:22
  • 1
    maybe if that happens is better u put a warning like "If you are seeing this message is because you have disabled javascript in your browser". Or something like that. In now days no one disables javascript. – CaRRaSKo Jan 23 '15 at 12:55
0
$_SESSION["image_path"] = $_POST['upload'];
<input type="file" id="product_images"<?php values= if(empty($_session['image_path'])) {} else { echo $_session['image_path']; } ?>class="hidden" name="upload[]">

after you retrieved ,Destroy the session

Thamaraiselvam
  • 6,961
  • 8
  • 45
  • 71
0

Try to use pattern in your input bar that will help you , you can do it very easily

http://www.wufoo.com/html5/attributes/10-pattern.html http://www.w3schools.com/tags/att_input_pattern.asp

Thamaraiselvam
  • 6,961
  • 8
  • 45
  • 71