0

I can't work out why this isn't working. I'm sure it's probably something small but I keep scratching my head. Below are my HTML and PHP.

form.html

<form action="result" method="post">
   <input type="text" class="form-control" name="hello">
   <input type="submit" class="btn btn-primary" value="Submit">
</form>

result.php (.htaccess is set to allow without .PHP and I receive the same issue when including .PHP in the action)

<?php

  if($_SERVER['REQUEST_METHOD'] == 'POST')
  {
     echo "POST<br>";
  }
                                
  print_r($_POST);

?>

Submitting the form sends you to result.php and POST is displayed, but $_POST is empty.

EDIT: .htaccess

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ $1 [NE,R=302,L]

Cheers in advance.

Spoon
  • 134
  • 1
  • 10
  • 2
    `action="result.php"` instead of `action="result"` in `
    `
    – Chilarai Aug 20 '20 at 10:04
  • 3
    Show us what yout .htaccess actually contains then. This sounds like the typical case where you lose the post data due to an _external_ redirect, which the browser follows by making a _GET_ request now. – CBroe Aug 20 '20 at 10:07
  • Hi @CBroe I've included the .htaccess - cheers for your help so far! – Spoon Aug 20 '20 at 10:09
  • 1
    Hey @Chilarai, I've tried that and it, unfortunately, doesn't make a difference. I think CBroe could be on the right tracks with the .htaccess – Spoon Aug 20 '20 at 10:09
  • [How to preserve POST data via ajax request after a .htaccess redirect?](https://stackoverflow.com/q/13886631/2943403) – mickmackusa Aug 20 '20 at 10:16
  • Hi @mickmackusa I'm really grateful for the reply. The answer to the question you've just commented leads me to another question - how would one go about changing it to a rewrite and not a redirect? Thanks! – Spoon Aug 20 '20 at 10:19

1 Answers1

0

With the help of @mickmackusa and @CBroe it was determined that the issue was with the .htaccess file.

It was redirecting instead of rewriting when removing the .PHP extension. The solution was to instead change the .htaccess to the following:

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

Thanks everyone for your help.

Spoon
  • 134
  • 1
  • 10