Php idea and code for simulating asp. netwebFrom button submission events

Source: Internet
Author: User
This article mainly introduces php asp simulation. the idea and code of the netwebFrom button to submit the event. if you need it, you can refer to the php project development required by the company. php is just getting started. during the process of submitting the write button, the button events in asp.net are better. Let's take a look at the following code,

The code is as follows:


Require_once '../inc/EventHelper. php ';

Function Page_Load ()
{
Echo 'runs at any time
';

If (! Page: IsPostBack ())
{
Echo 'load product category
';
If ($ _ GET ['cmd'] = 'edit ')
{
Echo 'modify and load 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:

The code is as follows:


Class Page
{
// Whether to send data back, 1: Yes
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.