Jump to content

Retaining the file name in a form


86Stang

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/182536-retaining-the-file-name-in-a-form/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.