puiu91
6/15/2016 - 5:45 PM

PHP Handling Request Method in Controller

PHP Handling Request Method in Controller

<?php

[...]

public function requestMethodHandler()
{
    if ($_SERVER['REQUEST_METHOD'] === 'POST' && $_POST['submitButton'] === 'true')  {
        $this->handlePost($_POST);
    } elseif ($_SERVER['REQUEST_METHOD'] === 'GET') {
        $this->handleGet();
    } else {
        $this->redirectTo404();
    }
}
<form method="post" enctype="application/x-www-form-urlencoded" action="">
  <input type="text" name"username">
  <button type="submit" name="submitButton" value="true"></button>
</form>