Home  >  Article  >  Backend Development  >  PHP simulation asp.net webFrom button submission event ideas and code_PHP tutorial

PHP simulation asp.net webFrom button submission event ideas and code_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:17:55951browse

Since the company needs project development in PHP, and I have just started using PHP, in the process of writing button submissions, the button events in asp.net are better. First look at the code below,

Copy code The code is as follows:

require_once '../inc/EventHelper.php';

function Page_Load()
{
echo 'Will run at any time
';

if(!Page::IsPostBack())
{
echo 'Load product category
';
                                                                                                                                                                                                                                          ;
}
}
}

function bAdd_Click(){

//Comm::CheckQX('Product Management_Add');
echo "bAdd_Click
";
}

function bEdit_Click()

{

//Comm::CheckQX('Product Management_Modification');
echo 'proID='.$_GET['proID'].' echo "bEdit_Click
";
}

function sdfsdfdsf_Click()

{

echo "e44444444444444444444
";
}

?>

 






Those who have done asp.net development should be familiar with the above code, 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 the [Add] button is clicked (let’s call it that, function seems to mean function). Similarly, the bEdit_Click event is automatically run when the [Modify] button is clicked. There is no need for too many parameter changes or too many files. If the page function is not very complex, this mode can be used for rapid development.

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

Copy code The code is as follows:

class Page
{
//Whether to post data back, 1: Yes
public static function IsPostBack()
global $SYSRunEvent Name ;
             return !empty($SYSRunEventName);                                                                               $SYSRunEventName;

$arrEvent=get_defined_functions();
$arrEventUser=$arrEvent['user'];

$arr=array_keys($_POST);
foreach($arr as $row)<​​​                $name1=str_ireplace('_click','',$row1);
                                                                            ​break;
break; }
}

if(!empty($SYSRunEventName ))
                                                                                                      exists('Page_Load'))
               Page_Load();

                                            strtolower($SYSRunEventName);

if(Page::IsPostBack())
                                               > }
}

    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();
?>

以上功能大家可以测试下,在我php5.4可以运行成功,不过在安全性方面还没考虑过多,看过一些文章php会有可能通过客户端执行php代码,因为php很许多实用的功能特性。

关于Comm::GetParam,由于经常需要获取get方式的参数,或修改参数,如分页时需要保留所有url参数,只修改分页参数(如page=5),所以就自行写了一些代码。

主要利用php以下几个特点:

function_exists
get_defined_functions

以及利用常用的表单提交原理,利用submit提交原理 实现功能的。

由于时间仓促,来不及说明具体原理,还请见谅,代码大家都可以看懂的。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/621707.htmlTechArticle由于公司需要php方面的项目开发,php刚刚入门,在写按钮提交过程中,asp.net里的按钮事件更好些。先看下面的代码, 复制代码 代码如下...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn