PHP analog asp.net webfrom button Submit Event Instance _php instance

Source: Internet
Author: User

Because the company needs PHP project development, PHP is just getting started, in the Write button submission process, ASP.net button events better. First look at the following code,

?
Require_once '.. /inc/eventhelper.php ';

function Page_Load ()
{
echo ' will run <br> at all times;

if (! Page::ispostback ())
{
echo ' loading product Classification <br> ';
if ($_get[' cmd ']== ' edit ') 
{
echo ' modifies the product information needed to be modified <br> '
;
}

}} function Badd_click ()
{
//COMM::CHECKQX (' Product management _ add ');
echo "badd_click<br>";
}

function Bedit_click ()
{
//COMM::CHECKQX (' Product Management _ Modify ');
Echo ' proid= '. $_get[' proid '. ' <br> ';
echo "bedit_click<br>";
}

function Sdfsdfdsf_click ()
{
echo "e44444444444444444444<br>";
}

? >
<form name= "AA" method= "post" action= "<?=comm::getparam ()?>" > <input type= "
submit" Name= "Badd" Value= "Add"/>
<input type= "Submit" Name= "BEdit" value= "Modify"/> <input type= "
submit" Name= " SDFSDFDSF "value=" ewrewrewr "/>
</form>

have done asp.net development of the above code should be a bit familiar, such as: Page_load,page.ispostback,badd_click, these are very similar to ASP.net events.

The above code runs the Badd_click function when clicking the "Add" button (for the time being, function seems to be the meaning of functions), similarly, click the "Modify" button to automatically run the Bedit_click event. Do not need too much parameter changes, and do not need too many files, if the page function is not very complex situation, with this model can be quickly developed.

Here's a look at the code for eventhelper.php this file:

?
Class Page {//whether to postback the data, 1: Is the public static function IsPostBack () {global $SYSRunEventName; return!empty ($SYSRunEventName);

//Load and Execute 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 $row 1) {$name 1=str_ireplace (' _click ', ', ', $row 1
);

if ($name = = $name 1) {$SYSRunEventName = $row 1; 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 ();?>

The above features can be tested, in my php5.4 can run successfully, but in the security aspect has not been considered too much, read some articles PHP will probably execute PHP code through the client, because PHP is a lot of practical features.

With regard to Comm::getparam, because you often need to get the parameters of getting method, or modify parameters, such as paging the need to retain all the URL parameters, only to modify the paging parameters (such as page=5), so you write some code.

The main use of PHP following several features:

Function_exists
Get_defined_functions

and using the common form submission principle, using the submit submission principle to realize the function.

Because of time haste, too late to explain the specific principles, but also forgive me, the code can be read.

Related Article

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.