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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.