Jump to content

Fields Of Feedback Form Stilll Run When I Not Fill In Form


hunglduc

Recommended Posts

i used these code but i see the function isset() not correct like w3schools said. when i not fill in the form, and press the button submit, these code still runi don't understand the function isset() like this page said

<html><body><?phpif (isset($_REQUEST['email']))//if "email" is filled out, send email  {  //send email  $email = $_REQUEST['email'];   $subject = $_REQUEST['subject'];  $message = $_REQUEST['message'];  mail( "someone@example.com", "Subject: $subject",  $message, "From: $email" );  echo "Thank you for using our mail form";  }else//if "email" is not filled out, display the form  {  echo "<form method='post' action='mailform.php'>  Email: <input name='email' type='text' /><br />  Subject: <input name='subject' type='text' /><br />  Message:<br />  <textarea name='message' rows='15' cols='40'>  </textarea><br />  <input type='submit' />  </form>";  }?></body></html>

Link to comment
Share on other sites

isset simply checks if the string "email" has a value or not (ie you have entered an e-mail address in the form).The script will still run but should ignore the code in the "if" statement (which sends the e-mail) and run the "else" which re-displays the form.If you are looking for the page to not reload when an e-mail address is not entered then you will need to use javascript to validate the form first and only allow the form to submit if the email section is filled in.

Link to comment
Share on other sites

isset is only checking if a variable exists. It doesn't check for a value, only if it even exists. When you submit the form everything exists. It might not have a value, but it's there. You can use empty if you want to check if it's actually set to a non-empty value in addition to being defined. e.g.:if (!empty($_REQUEST['email']))Also, it's better to use $_GET or $_POST instead of $_REQUEST.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...