isset($_POST['submit']) vs $_SERVER['REQUEST_METHOD']=='POST'
php
Solution
These mean two different things. The first, checks to see if when the form was submitted the parameter `submit` was passed. Many use this snippet to verify that a form has been sent. This works because the submit button is technically an `<input>` so it's value is sent along with any other elements that were part of the form.
<?php
if(isset($_POST['submit'])) { // This way form and form logic can be adjacent to each other
// Logic
}
?>
<form method='POST' action='<?= $_SERVER['REQUEST_URI'] ?>'>
<!--- other form stuff -->
<input type="submit" name="submit" value="Send!" />
</form>
The second snippet tests if the form was submitted with the POST method. This doesn't necessarily mean that the form button was pushed. If it wasn't submitted with POST, then the superglobal `$_POST` would be empty.
Problem
I have come across scripts that use: ``` isset($_POST['submit']) ``` as well as code that uses: ``` $_SERVER['REQUEST_METHOD']=='POST' ``` I was wondering the difference between these two and which method is best.