<p>Discovered there was an NGINX config that was adding trailing slashes to URLs. Posting to the URL /api/controller-action was getting changed to /api/controller-action/ and emptying the POST data.</p>

CC BY-SA 4.0
2024-05-15T11:37:52.947Z
2024-05-15T11:37:52.947Z
Jaytrix
<p>Trying to debug a form issue which is only happening on a live server (it works on our local environments).</p>
<p>The form makes a fetch request (using Javascript) to a route in <code>routes.php</code> which goes to a controller. I can see the data sent to the controller has the email address in the <code>email</code> field, but when it comes to the controller the field is empty.</p>
<p>I'm using:</p>
<pre><code>$request = Craft::$app-&gt;getRequest();
$emailAddress = $request-&gt;getBodyParam('email');
</code></pre>
<p><code>$emailAddress</code> is always empty on the live/staging/dev server.</p>
<p>The main difference between our local environments (we're using a mix of Mac, Windows, Herd, and DDEV) is that the servers are running REDDIS.</p>
<p>I've found similar issues with Craft 3 on here, but we're using Craft 5.1.2.</p>

<controller><craft5>
getBodyParam('email') is empty on live server
# getBodyParam('email') is empty on live server

(Asked by: username_0 on 2024-05-14)

Trying to debug a form issue which is only happening on a live server (it works on our local environments).
The form makes a fetch request (using Javascript) to a route in routes.php which goes to a controller. I can see the data sent to the controller has the email address in the email field, but when it comes to the controller the field is empty.
I'm using:
$request = Craft::$app->getRequest();
$emailAddress = $request->getBodyParam('email');

$emailAddress is always empty on the live/staging/dev server.
The main difference between our local environments (we're using a mix of Mac, Windows, Herd, and DDEV) is that the servers are running REDDIS.
I've found similar issues with Craft 3 on here, but we're using Craft 5.1.2.

**Tags:** controller, craft5

---

## 1 answers

### Answer by username_0 on 2024-05-15. Score: 2

Discovered there was an NGINX config that was adding trailing slashes to URLs. Posting to the URL /api/controller-action was getting changed to /api/controller-action/ and emptying the POST data.


---

