The best way to explain is by using an example. Suppose that you have a label on the field and a button. When you click the button you want to show the current time on the label.

First create a new module (no database connection) and design a simple form with two rows with each one column. Put a label component on the first row/column and a button on the other. It should look something like this.



Then select the form. PHsPeed will change the property editor and select the properties of the form.  Select the PHP-Events tab to show the available events.


Invoke the onsubmit event


Now click in the onSubmitForm to open up the property editor and click the … icon

This will open up the PHP editor:



The $app is the basic application reference and contains references to all your components. However, to access these components you need to know the real name which is different than the shown name.

Naming conventions

Applications can have headers and footers, and they all can contain components. As PHsPeed by default generates a component name, based upon its type and sequence, it is possible that when you combine a header with a module that there will be more than one label_1. To avoid these naming problems, the generator will make some modifications to the name to assure its uniqueness. It does that by adding the module name to the component. So label_1 becomes main_label_1. 

However, the component is a property of the application component. To access the label_1 on the form you need to access the variable from the application component which is $app. So the full reference to the label_1 object is $app->main_label_1 as can be seen in this code snippet that is generated by the generator:


class main extends spapplication {
    public   $action;
    protected $main_root_1;
    protected $main_form_1;
    protected $main_panel_1;
    protected $main_label_1;
    protected $main_btn_1;
    protected $main_csrftoken;   


So, if you want to set the current time to the label component, then you must know that the label component has two properties that are used to display its value. The first one is label, and is the label of the field. The second one is the value and represents the content of the field. Every visual component has these properties. So the edit field has a label and value property etc. 

To obtain the date and time from php and assign it to the label value we need to write:


$app->main_label_1->value=date(“Y-m-d H:i:s”);


If the $app is not passed in the event header then it will be available as a property of the current component. Then it would be:


$this->app->main_label_1->value=date(“Y-m-d H:i:s”);


Complex? Yes it is. Can it be simplified? YES!!


To access form variables, and not to have worries about the above you can use the short $$ notation. By using $$ the generator ‘knows’ that it has to replace it by a correct reference to the component. So 


$this->app->main_label_1->value=date(“Y-m-d H:i:s”);


Becomes


$$label_1->value = date(“Y-m-d H:i:s”);


So if you wonder why the $$ notation is used in the demo applications then you know now. What other lesson does this give us? Well, the naming convention is also used in the html pages. So if you need to locate the label_1 in your html page then you need to search for:


Id_main_label_1 for the id of the field and Main_label_1 for the name of the field. 


This method is used consistently. So if you have to write your own JavaScript or need to apply classes then you know how the field is called in the generated html. Depending on the type of developer you are, it is rare that you have to write JavaScript, but if you need, then you can.