Php simulates asp. netwebFrom button to submit event instance _ php instance

Source: Internet
Author: User
Php project development is required. php is just getting started. During the write button submission process, the button events in asp.net are better. There is an example below, you can check that the company needs php project development. php is just getting started. In the process of writing button submission, the button events in asp.net are better. Let's take a look at the following code,

<? Require_once '../inc/EventHelper. php'; function Page_Load () {echo' will run at any time
'; If (! Page: IsPostBack () {echo 'Load product category
'; If ($ _ GET ['cmd'] = 'edit') {echo' modifies and loads the product information to be modified.
';}} Function bAdd_Click () {// Comm: CheckQX ('product management_add'); echo "bAdd_Click
";} Function bEdit_Click () {// Comm: CheckQX ('product management_modify'); echo 'proid = '. $ _ GET ['proid'].'
'; Echo "bEdit_Click
";} Function sdfsdfdsf_Click () {echo" e44444444444444444444
";}?>

 

The above code, such as Page_Load, Page. IsPostback, and bAdd_Click, is familiar with asp.net development.

The above code runs the bAdd_Click function when you click the Add button (function seems to be the function). Similarly, click Modify to automatically run the bEdit_Click event. There is no need for too many parameter changes or too many files. If the page features are not very complex, you can use this mode for rapid development.

Let's take a look at the code of the EventHelper. php file:

<? Class Page {// whether to send data back. 1: public static function IsPostBack () {global $ SYSRunEventName; return! Empty ($ SYSRunEventName);} // load and execute the event function EventLoad () {global $ SYSRunEventName; $ arrEvent = get_defined_functions (); $ arrEventUser = $ arrEvent ['user']; $ arr = array_keys ($ _ POST); foreach ($ arr as $ row) {$ name = strtolower ($ row); foreach ($ arrEventUser as $ row1) {$ name1 = str_ireplace ('_ click', '', $ row1); if ($ name = $ name1) {$ SYSRunEventName = $ row1; break ;}} if (! Empty ($ SYSRunEventName) {break ;}} if (function_exists ('page _ load') Page_Load (); $ SYSRunEventRunName = strtolower ($ SYSRunEventName); if (Page :: isPostBack () {$ SYSRunEventName () ;}} class Comm {public static function GetParam ($ params = array (), $ cmd = 'addoverride ') {$ allParam = array (); if ($ cmd = 'addoverride') {$ arrKeys = array_keys ($ params); foreach ($ arrKeys as $ row) {if (! In_array ($ row, array_keys ($ allParam) $ allParam [$ row] = $ params [$ row] ;}} else if ($ cmd = 'del ') {foreach ($ params as $ row) {unset ($ _ GET [$ row]) ;}}$ arrKeys = array_keys ($ _ GET ); foreach ($ arrKeys as $ row) {if (! In_array ($ row, array_keys ($ allParam) $ allParam [$ row] =_ _ GET [$ row] ;}$ p = ''; $ arrKeys = array_keys ($ allParam); foreach ($ arrKeys as $ row) {$ p. = $ row. '= '. $ allParam [$ row]. '&';} return rtrim ($ p, '&') ;}} Page: EventLoad ();?>

You can test the above functions. I have run php5.4 successfully, but I have not considered much about the security. I have read some articles about php and may execute php code on the client, because php has many practical features.

For Comm: GetParam, it is often necessary to obtain get parameters or modify parameters. For example, if all url parameters need to be retained during paging, only paging parameters (such as page = 5) are modified ), so I wrote some code on my own.

It mainly utilizes the following features of php:

Function_exists
Get_defined_functions

And uses common form submission principles to implement functions.

Due to the rush of time, it is too late to describe the specific principles. Please forgive me. You can understand the code.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.