Eggzorcist Posted December 26, 2010 Share Posted December 26, 2010 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 https://forums.phpfreaks.com/topic/222652-problematic-isset_postsubmit/ Share on other sites More sharing options...
Pikachu2000 Posted December 26, 2010 Share Posted December 26, 2010 What about it "isn't working"? Link to comment https://forums.phpfreaks.com/topic/222652-problematic-isset_postsubmit/#findComment-1151461 Share on other sites More sharing options...
Eggzorcist Posted December 26, 2010 Author Share Posted December 26, 2010 I found what was the problem. the input in the html must be the type of 'submit' rather than simply a type='button'. Thanks! Link to comment https://forums.phpfreaks.com/topic/222652-problematic-isset_postsubmit/#findComment-1151463 Share on other sites More sharing options...
Dragosvr92 Posted December 26, 2010 Share Posted December 26, 2010 you should have a look at this new HTML5 Function http://www.the-art-of-web.com/html/html5-form-validation/ Email Address: <input type="email" name="email" required placeholder="Enter a valid email address"> Link to comment https://forums.phpfreaks.com/topic/222652-problematic-isset_postsubmit/#findComment-1151484 Share on other sites More sharing options...
the182guy Posted December 26, 2010 Share Posted December 26, 2010 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 https://forums.phpfreaks.com/topic/222652-problematic-isset_postsubmit/#findComment-1151605 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.