php simulates the idea and code of the ES1en.net webFrom button to submit the event

  • 2020-11-20 06:02:27
  • OfStack

php is just getting started because the company needs to develop php projects. The button events in ES3en.net are better for write button submission. So let's look at the following code,


<?
require_once '../inc/EventHelper.php';
function Page_Load()
{
    echo ' It will run at any time <br>';

    if(!Page::IsPostBack())
    {
        echo ' Load product classification <br>';
        if($_GET['cmd']=='edit')    
        {
            echo ' Modify load the product information that needs to be modified <br>';
        }
    }
}
function bAdd_Click()
{
    //Comm::CheckQX(' Product management _ add ');
    echo "bAdd_Click<br>";
}
function bEdit_Click()
{
    //Comm::CheckQX(' Product management _ Modify the ');
    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 the " />
    <input type="submit" name="sdfsdfdsf" value="ewrewrewr" />
</form>

Those who have done asp.net should be familiar with the above code, such as Page_Load, Page.IsPostback, bAdd_Click, which are similar to asp.net events.

The above code runs the bAdd_Click function when you click the "add" button. Similarly, clicking the "Modify" button automatically runs the bEdit_Click event. It doesn't require too many parameter changes or too many files, and can be developed quickly if the page function is not too complex.

Here's the code for the file EventHelper.php:


<?
    class Page
    {
        // Whether to post back the data, 1: is 
        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();
?>

The above functions can be tested, es36EN 5.4 can run successfully, but in the security aspect has not considered too much, read some articles php will be possible to execute php code through the client, because php is a lot of practical features.

With respect to Comm::GetParam, I wrote some code myself because I often needed to get arguments in get mode or change them, such as when paging, I needed to keep all url arguments and only change the paging parameters (such as page=5).

The following features of php are mainly used:

function_exists
get_defined_functions

And using the common form submission principle, using submit submission principle to achieve the function.

Due to the time is too short to explain the specific principle, please forgive me, the code we can understand.


Related articles: