86Stang Posted November 22, 2009 Share Posted November 22, 2009 I've got a small form where the user can upload an image along with a small comment. The image field and comments are both required. I've got no problem checking $_POST to see if the comment is not empty but no matter what I try, I can't get the file field to hold the data the user put in. In other words, if the user browses to a file to upload but leaves no comment, I want it to tell them they need to enter a comment (which I can currently do) but also keep the data they entered in the file field so they don't have to go browse for the file again. Here's the section of code to what I've got: if (!empty ($_POST)){ if (empty ($_POST['file'])){ $msg .="This is a required field."; } if (empty ($_POST['comment'])){ $msg .="Comment is required."; } } <form action="post.php" method="post" enctype="multipart/form-data"> <input type="file" name="file" value="<?php echo $_POST['file'] ?>"> <label>Comment</label><input type="text" name="comment" id="comment" value="<?php echo $_POST['comment'] ?> /> <input type="image" src="img/btn_form_post.gif" alt="Submit" class="form_btn" /><label> </label> </form> Quote Link to comment https://forums.phpfreaks.com/topic/182536-retaining-the-file-name-in-a-form/ Share on other sites More sharing options...
seksislav Posted November 22, 2009 Share Posted November 22, 2009 it shouldn't be $_POST['file'], but $_FILES['file']['error'] and so on do check some things on $_FILES and say if u still have trouble. Quote Link to comment https://forums.phpfreaks.com/topic/182536-retaining-the-file-name-in-a-form/#findComment-963442 Share on other sites More sharing options...
mikesta707 Posted November 22, 2009 Share Posted November 22, 2009 most modern browsers will ignore the value attribute of input file fields for security concerns Quote Link to comment https://forums.phpfreaks.com/topic/182536-retaining-the-file-name-in-a-form/#findComment-963455 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.