开发者

Is there any way of handling events in php

Is 开发者_StackOverflow中文版there any way to handle events in php, I'm looking for a way to handle event's like posting a form. Thanks, Sreejith


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
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜