Why can't Code Igniter detect that my form is being submitted via POST?

Go To StackoverFlow.com


I have a form in a Code Igniter view in my jQuery Mobile application.

<form action="<?= BASE_PAGE_URL ?>settings" method="post" id="settingsForm">
    <div data-role="fieldcontain">
        <label for="firstName">First Name</label>
        <input type="text" name="firstName" id="firstName" value="" placeholder="First Name" />
    <div data-role="fieldcontain">
        <label for="lastName">Last Name</label>
        <input type="text" name="lastName" id="lastName" value="" placeholder="Last Name" />
    <input type="hidden" name="purpose" value="register" />
    <input type="submit" name="submit" value="Register" />

However, when I write this code into the controller method that the URL specified by action leads to:

echo ($_SERVER['REQUEST_METHOD'] == 'POST') ? "yay" : "nay";

"nay" is written to the page when I hit the submit button. How come Code Igniter cannot tell that I am submitting a post request?

2012-04-04 05:28
by John Hoffman
Have you tried echo $_SERVER['REQUEST_METHOD'] to see what that says? Could be just a case issue (i.e. POST vs post) - micflan 2012-04-04 05:38
Thanks, $_SERVER['REQUEST_METHOD'] is strangely returning "GET" after I hit submit. I wonder why - John Hoffman 2012-04-04 05:48
try looking at the debugger to see if the request is sent as a get or post - Joseph 2012-04-04 05:52
Thank you, what is the debugger - John Hoffman 2012-04-04 05:52


If you want to determine if you have POST data or if request was a POST, use post() method from the input class


//returns FALSE if no POST data
//returns the POST array if there is data (hence, a POST)
//returns a specific data from the array if you provide "index"
2012-04-04 05:37
by Joseph


It can be cause of register_globals. Use


OR CI input class

2012-04-04 05:42
by safarov


I wonder if your form is returning a post request as you expect, but that something is redirecting immediately afterwards, which you're seeing as a GET? Try putting a temporary exit() immediately into the form-handling action; I suspect that will come out as POST.

2012-04-04 06:04
by halfer