I am new with CodeIgniter..
I have weird issue, i can’t get POST request data inside controller.
I thought it is because some inputs, i removed and left only one (in addition to CodeIgniter’s generated csrf_test_name). It didn’t help, then i thought it is because camelCase style name (saveAgreement) and i replaced it with just save, and this also didn’t help..
Of course i refreshed the page, tried with another browser etc.
I share a part of my code with you..
<form action="https://test.mydomain.ee/agreements/saveAgreement/" method="post" accept-charset="utf-8">
<input type="hidden" name="csrf_test_name" value="fefe3fb945d5d967bb962b5f1a8931eb">
<input type="text" name="testin">
<button>Salvesta</button>
<a href="https://test.mydomain.ee/agreements">Loobu</a>
</form>
And in controller i just try do die-dump the request content and it returns array()
function saveAgreement()
{
dd($this->request->getPost());
}
All other forms in same and in other controllers work just fine with same code:
$this->request->getPost()
Thanks for any help!
2
Answers
This was due to the slash in the end of form action parameter. It worked just fine if i changed it to:
When using CSRF it’s a good idea to use the Codeigniter Form Class:
also, in your controller to grab the identified elements so you are not getting injected items:
Finally, in the controller, to grab all items being posted from the form, I still use:
Helps to catch form element misspellings.