Jump to content

[SOLVED] Required fields in form


mallen

Recommended Posts

This will add the entered data into the fields if something was entered before. Also, you were only closing the input fields with > in your IF statement.

   <p>From name: <input type="text" name="fromname" value="<?php echo @$_POST['fromname']; ?>"><?php if (isset($missing) && in_array('fromname', $missing)) { ?><p>Please enter your name</p><?php } ?>
   <p>From e-mail: <input type="text" name="fromemail" value="<?php echo @$_POST['fromemail']; ?>"><?php if (isset($missing) && in_array('fromemail', $missing)) { ?><p>Please enter your email</p><?php } ?>

Link to comment
Share on other sites

Thanks F1FAN. I had this before I saw your post. It works but doesn't remember the "filename" field.

 

 

<p>Send an e-mail with an attachment:</p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"
enctype="multipart/form-data" name="form1">
<p>From name: <input type="text" name="fromname" <?php if (isset($missing)) {
echo 'value="'.htmlentities($_POST['fromname']).'"';} ?>
<p>From e-mail: <input type="text" name="fromemail" <?php if (isset($missing)) {
echo 'value="'.htmlentities($_POST['fromemail']).'"';} ?>
<p>File: <input type="file" name="filename" <?php if (isset($missing)) {
echo 'value="'.htmlentities($_POST['filename']).'"';} ?>
<p><input type="submit" name="Submit" value="Submit">

Link to comment
Share on other sites

Yes, you cannot assign a value to a file type input. This could be a big security problem if you could. For example, you would be able to assign a value (possibly a file on the user's computer) and hide it from the user. Then if the user posted a form, they could be uploading a file without knowing it.

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.