Course Content

Expand All

Advanced Form Template Rules

In Deepser you can define the rules for loading Form Templates via PHP script.

It is useful to be able to define conditions “manually” by scripts when they are too complex or particular to be expressed by query-builder.

To define a rule by scripting, go to the configuration menu of the Form Template, move to the tab (on top) Edit Rules and click the icon </> above the query-builder  (as shown in the picture).

In this area you will find the code automatically generated by query-builder that you can integrate or replace with custom PHP code.

EXAMPLE: Template for IT Second Level members

In the following example we want to make a template visible only to users who are members of a specific group: IT Second Level.

To do this you need to enter the following PHP code in the Rules scripting area.

//retrieve the current user
$currentUser = Deep::helper('deep_admin')->getCurrentUser();
//IT Second Level group id = 5
//check if the user is in IT Second Level group
    //original condition generated by the query-bulder
    if( $this->getModel()->getData('type_id')==1 &&
            ( $this->getModel()->getData('category1')==5 ||
                $this->getModel()->getData('category1')==17 ||
                $this->getModel()->getData('category1')==2 )){
        //if both conditions are verified the template form is loaded
        return true;
    //else return false and evaluate the rules of the next template
    return false;