Jump to content

if "is post"


phppaper

Recommended Posts

<?php
if ($_REQUEST['test']=='post') {
	echo "The field did contain the text 'post'.";
} else {
	echo "The field did not contain the text 'post'.";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<title>form test</title>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
</head>
<body>
	<form action="<?php echo $PHP_SELF;?>" method="POST">
		<input type="text" name="test" id="test" />
		<input type="submit" value="submit" />
	</form>
</body>
</html>

 

Try playing around with this... It checks to see if something was submitted (which it sounds like what you are asking). Additionally, if you are asking specifically if something was posted from a variable called post, change the php code to look something like this:

<?php
if ($_REQUEST['test']=='post') {
	echo "The field did contain the text 'post'.";
} else {
	echo "The field did not contain the text 'post'.";
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/221726-if-is-post/#findComment-1147551
Share on other sites

You should use something like this

<?php
// Returns TRUE if request is post otherwise FALSE
function isPost()
{
    return (strtolower($_SERVER['REQUEST_METHOD']) === "post") ? TRUE : FALSE;
}

// Now you can do:
if(isPost())
{
    // Do this if it was post
}
else
{
    // Do this when it isn't post
}
?>

Link to comment
https://forums.phpfreaks.com/topic/221726-if-is-post/#findComment-1148016
Share on other sites

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.