Jump to content

problematic isset($_POST['submit'])...


Eggzorcist

Recommended Posts

I'm not sure why this code isn't working... I've done this many times before and this time it isn't working at all...

 

Here's the code I'm using:

<?php

if(isset($_POST['submit'])){
if(filter_var($_POST['value1'], FILTER_VALIDATE_EMAIL)){
	echo "Value is a valid email address.";
	} else {
	echo "Value is NOT a valid email address.";	
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST">
<input name="value1" type="text" id="value1" size="40" />
<input id="submit" name="submit" value="Validate Value" type="button" />
</form>
</body>
</html>

 

I'm wondering whether anything has changed, but I don't see how this couldn't work.

 

Thanks for any additional information!

 

Link to comment
Share on other sites

1. Don't use isset($_POST['submit']) to check if a form has been submitted/posted, use this

 

if($_SERVER['REQUEST_METHOD'] == 'POST')
{
   //submitted
}

 

Why? Because if you press the enter key on a field to submit a form on some versions of Internet Explorer and other browsers, the submit button does not get sent as a posted variable, so your script would not detect the form was posted.

 

2. Don't use action="<?php echo $_SERVER['PHP_SELF'] ?>" on a form because it is vulnerable to XSS attacks.

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.