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 } ?>

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">

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.

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.