Is there any way to handle events in php, I'm looking for a way to handle event's like posting a form. Thanks, Sreejith
-
PHP runs on server side. It can't handle client side UI events. – Pekka Feb 05 '11 at 17:45
-
9This question is vague and confusing. – Dan Grossman Feb 05 '11 at 17:46
-
@Darin, To the server mostly to index.php @Pekka, I was thinking of events like in ASP @Dan, Sorry for that, I was looking for a way similar to ASP events – sreejith Feb 05 '11 at 17:48
2 Answers
The reason (probably) why people are confused by "PHP" + "events" is that there is no such thing as events in PHP technically speaking. PHP scripts receive "requests", and you can discern requests via the $_POST
and $_GET
global variables. (There is also the $_REQUEST
variable, but it's use is... sometimes questionable.)
Anyhow, there is no concept of "form submission" in PHP either; this is a client-side concept. Simply because you can perform a POST or a GET request to a PHP script with or without going through a form
element and, from a PHP point of view, you cannot tell the difference.
Also, since a PHP request is single threaded (to the extend of my knowledge at least), your "event" will probably look like this (for a POST request) :
if (isset($_POST['btn_submit'])) {
// we suppose that the submit button was pressed and the form was sent
// we suppose also that other data is also present in $_POST
//
// handle form post event here
}

- 1
- 1

- 51,409
- 25
- 133
- 214
Posting a form is not really an event: the page is just called (that's the only event you'll get as far as i know), but you can check for certain values to be present in $_GET
, $_POST
or the combined $_REQUEST
, and act on them.

- 64,065
- 16
- 119
- 163
-
Yes, I was actually looking to figure out a way if any event occurs when the server recieves the POST – sreejith Feb 05 '11 at 17:50
-
No real event, the server just receives a request for you page, but there is something in the `$_POST` variable.. and you can check for that ofcourse in your file. It's just your basic file-loading. As if you'd load the file without posting, or as if you're doing a reload. But then with extra data in those pre-mentioned vars. – Nanne Feb 05 '11 at 17:59