CodeIgniter Forums
How are you detecting postback? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How are you detecting postback? (/showthread.php?tid=23014)



How are you detecting postback? - El Forum - 09-26-2009

[eluser]Damien K.[/eluser]
How are you detecting postback?

No need to tell me how CI does it, because I already know. How are you doing it?


How are you detecting postback? - El Forum - 09-26-2009

[eluser]wiredesignz[/eluser]
Maybe you could explain how CI does it. Wink


How are you detecting postback? - El Forum - 09-26-2009

[eluser]Damien K.[/eluser]
Maybe I can't and was just bluffing. Smile

count($_POST) == 0


How are you detecting postback? - El Forum - 09-27-2009

[eluser]wabu[/eluser]
You could extend Controller and add something like the following (to MY_Controller):

Code:
function is_post() {
  return $_SERVER['REQUEST_METHOD'] == 'POST';
}



How are you detecting postback? - El Forum - 09-27-2009

[eluser]steelaz[/eluser]
My submit buttons usually have: name="submit", so I just:

Code:
if ($this->input->post('submit'))
{
    // do it
}



How are you detecting postback? - El Forum - 09-27-2009

[eluser]BrianDHall[/eluser]
I check for some specific required field, usually the most 'obvious' one, and I also have the tendency to put hidden fields in my forms that I check for to be definitive on just what form is being submitted. Some forms I actually use this to handle form submission in my constructor or MY_controller (I handle login this way, so if there is $this->input->post('login_request') is true I try to log the user in before doing anything else). The advantage there is that I can build any form, anywhere on the site, in any way I want and have it 'just work' so long as I stick the right hidden form field or even drop-down field option in a form somewhere.


How are you detecting postback? - El Forum - 09-27-2009

[eluser]Damien K.[/eluser]
Looks like all the intuitive ways to detect postback have been mentioned. Thanks, everyone, for all the feedbacks.

My implementation is the same as wabu's way, except I extend Form_validation instead.