PHPMaker
PHPMaker
PHPMaker
After loading the database, the database objects (tables, views, custom views and reports) will be shown in the left pane (the database
pane). Click on any table to go to the Field Setup Page and then select the Code tab (which contains Server Events, Client Scripts and
Custom Templates).
Note: For simplicity, we use "table" in the following description to refer to any of database object in the project. A database object can
be either a table, a view, a custom view or a report.
The treeview shows the available server events and client scripts that you can add to your project:
Table-Specific The set of events are table-specific, the events are applicable to the selected table only
Other The events are applicable to some common pages in the project only
Global The JavaScript are included in all pages with header and footer
Table-Specific The JavaScript are table-specific, they are included to pages for the selected table only
Other The JavaScript are included in some common pages in the project only
To add your custom scripts to the server events or client scripts, select an item in the treeview, then enter your code in the editor.
The editor supports Find and Replace. Press Ctrl-F to open the Find dialog and press Ctrl-H to open the Replace dialog.
You can click the [Clear] button to discard the existing code and reset template code for the server event or client script.
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 2 of 47
Code Repository
PHPMaker provides a Code Repository for easy reuse of your code across projects and sharing with other users. Click the [Code
Repository] button to open it, categorized reusable code will be displayed:
You can add the code to the editor by clicking the [Add to Editor] button. The reusable code is stored in XML files which reside in s
subfolder name "code" under the installation folder. The format of the XML files is simple, there are 3 parts:
There are a few example files in the "code" folder, you can copy and modify for your own code and then save them under the "code"
folder for reuse.
Server Events
In general, server events are fired in the following order: (not all pages are the same)
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 3 of 47
Notes
1. The page classes inherit from the table classes, so you can use $this in the page class methods to access table class
members. For backward compatibility, the table object is kept and it is an alias of the page object, so you can also use $this
in the table class methods to access page class members.
2. The Page_Unload and Page_Unloaded are server side events to be fired every time the page is accessed and before the
HTML is outputted to the browser on the client side. They are NOT events to be fired before you leave the page and reload
the page or go to another page. For example, if you submit a form in the page, usually it submits to the page itself, you are
actually reloading the page, all server events will be fired again. For another example, if you click a hyperlink which links to
another page, the page on the server side is not even accessed again and no server events for the page will be fired.
3. If a server event is a global function, there is NO $this in the function context. If you want to refer to the current page object,
you can use the global function CurrentPage().
4. In the following table, the <fieldname> in code, e.g. in $this-><fieldname>-><property> or x_<fieldname>, represents the field
variable name (see Database, Table and Field Variable Names). However, note that if the field name is quoted, e.g. as a key in
$rs['<fieldname>'], <fieldname> is the actual field name as in the database, not the field variable name.
5. Server events are functions or class methods, if you need to use global variables in the events, note the PHP variable scope,
you must use the global keyword or $GLOBALS.
Page_Head The code you entered in this event will be placed in the header.php before closing the <head> section.
You can use this event to can add your code in head section. Note: This is a global function.
For example, PHPMaker does NOT support jQuery UI, AdminLTE plugins, or other jQuery plugins, but
you can include them yourself. Then you can use the widgets using Startup Script (see below).
Example 1
Example 2
Example 3
You can even use both PHP and HTML, but in such case you MUST use <?php ... ?>, e.g.
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 4 of 47
Page_Foot The code you entered in this event will be placed in the footer.php after the <footer> section. You can
use this event to can add your code for the website. Note: This is a global function.
Note Control sidebar requires default AdminLTE layout and therefore does NOT work properly if
the Reset Layout Height setting is disabled (see Advanced Settings).
The generated script can apply JsRender templates automatically if the template is in the format of
<script type="text/html" class="ew-js-template">...</script>. Using these templates you can
change virtually everywhere of the whole layout. Note: The CSS class name "ew-js-template" is
mandatory and is case-sensitive.
Note If more than one templates have the same name, only the first template will
be used.
data-target (Required) The target (CSS selector) of the template. To be used with data-method
(see next).
Notes
1. This must be a valid CSS selector, otherwise the target cannot be found and
the template cannot be rendered.
2. Press F12 in browser, inspect the HTML elements, check the id and class
attributes to find the correct CSS selector of your target.
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 5 of 47
data-method (Optional) The jQuery method name to apply the template. In general, the template will
be rendered by:
$(<html>)[method](target);
$(target).html(<html>);
data-data (Optional) Data to be passed to the template. It must be a property name of the
ew.vars object or the window object. If you want to pass data to the template, make sure
you set the data first.
For example, menu data is set to ew.vars.menu and then data-data="menu" is set for the
menu template. You can override the default menu template by adding your own with
same name (i.e. data-name="menu") in Page_Foot event. Similarly for the multi-language
selector (data-name="languages") and the logged-in user dropdown panel (data-
name="login").
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 6 of 47
Database_Connecting This event will be called by all PHP pages before connecting to the database. Note: This is a global
function.
If general, the argument is an array with the following keys: host, port, user, pass, db. If Access, the key
is connectionstring. You can use this event to change the connection string (e.g. changing connection
info with server, or even connect to other databases).
Example 1
// MySQL/PostgreSQL
function Database_Connecting(&$info) {
//var_dump($info);
// assume the scripts are generated with connection info for local PC
if (CurrentUserIP() <> "127.0.0.1") { // not connecting to local PC
// connect to the production database
$info["host"] = "localhost";
$info["user"] = "xxx";
$info["pass"] = "yyy";
$info["db"] = "production_db";
}
}
Example 2
It is possible to use single login and common Dynamic User Levels for multiple projects provided that
ALL projects use the same project name and same Advanced Security tables (i.e. User Table, User Level
Table and User Level Permission Table). If all projects uses the same database and same Advanced
Security tables, then the latter condition is auto fulfilled. However, if the projects use different databases,
you can use this event to change the connection info so the user can get the Dynamic User Levels from
the common Advanced Security tables correctly during login, e.g.
// MySQL/PostgreSQL
function Database_Connecting(&$info) {
//var_dump($info);
if (preg_match('/login|userpriv/', CurrentPageID()) { // login.php or userpriv.php
// connect to the common database with the common Advanced Security tables
$info["host"] = "localhost";
$info["user"] = "xxx";
$info["pass"] = "yyy";
$info["db"] = "common_db";
}
}
Database_Connected This event will be fired by all PHP pages after connecting to the database. Note: This is a global
function.
The argument is the connection object, you can use it to execute your own statements.
Example
function Database_Connected(&$conn) {
$conn->Execute("CALL MyStoredProcedure");
}
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 7 of 47
Language_Load This event will be fired when the language file is loaded. You can use it to change the language phrases
if necessary. Note: This event is a language class member.
Example 1
function Language_Load() {
$this->setPhrase("MyID", "MyValue"); // Refer to language file for the actual phrase id
$this->setPhraseClass("MyID", "fa fa-xxx ew-icon"); // Refer to
https://fontawesome.com/v4.7.0/icons/ for icon name
}
Example 2
function Language_Load() {
$this->Type = "DROPDOWN"; // Set the Type, supported types are: LI/DROPDOWN (for used with
top Navbar) or SELECT/RADIO (NOT for used with top Navbar)
//$this->Template = "<My JsRender template>"; // OR use custom JsRender template
}
Page_Loading This event will be called by all PHP pages at the beginning of the page. If the pages involves database
connection, it will be called after connecting to the database and before the Page_Load event. Note:
This is a global function, NOT page class member.
Page_Rendering This event will be called by all PHP pages before outputting HTML for the page. Note: This is a global
function, NOT page class member.
Page_Unloaded This event will be called by all PHP pages at the end of the page. If the pages involves database
connection, it will be called before closing database connection and after the Page_Unload event. Note:
This is a global function, NOT page class member.
Global Code Code to be included in all PHP pages. This may contain your constants, variables, functions and classes.
Example 1
// Override ExportTableheader()
function ExportTableHeader() {
$this->Text .= "<div>" . $this->Table->TableCaption() . "</div>"; // Add table caption
parent::ExportTableHeader(); // Call the parent method
}
$EXPORT['excel'] = 'MyExportExcel'; // Replace the default ExportExcel class by your own class
Example 2
Add AWS SDK for PHP to composer.json (see Using User Code) and register Amazon S3 Stream Wrapper
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 8 of 47
User_CustomValidate For use with security. (See Security Settings) This event is fired before default user validation. You can
use this event to validate the user yourself. The arguments are the user name and password the user
entered. Return TRUE if the username and password pass your custom validation. Note: This event is a
security class member.
Notes
1. If you use "Windows" or "LDAP" authentication (see Advanced Settings), returning TRUE or
FALSE in this event does not matter. The user will be validated by Windows or LDAP later.
2. If you use "LDAP" authentication (see Advanced Settings), you can use this event to modify
the username and password, if necessary, for subsequent validation with LDAP server.
3. Default validation will continue after this event is fired. If you return TRUE, the user will
always pass the default validation and get the User ID and User Level, if any. If you return
FALSE, the default validation proceeds as normal. If you use Advanced Security, you still
need the user table to store user information such as User ID and User Level, although
the password field value can be empty or any value if you return TRUE.
Example
Remove the domain name to match the user name in user table (for User ID/Level Security, if enabled)
after Windows authentication, if the user table stores the user name without domain name.
Ldap_Validated For use with "LDAP" authentication (see Advanced Settings) only. This event is fired after
User_CustomValidate (see above). When this event is fired, the user bind is already done successfully,
but you can use this event to do further validation or to get some more information of the user from the
LDAP server. Return TRUE if the user your custom validation. Note: This event is a Ldap class member.
Example
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 9 of 47
User_Validated For use with security. (See Security Settings) This event is fired after validating the user with the user
table. Note: This event is a security class member.
Notes
1. This event is not fired for the hard-coded administrator (who is not an user in the user table).
2. If the user is found in the user table, the argument $rs is an array, you can get a field value
by $rs['<fieldname>']. If the user is not found, $rs is NULL. By default most user info is
already loaded into the global user profile object, Profile(), but the info does not include
the password field, BLOB fields, and memo fields, you can use this event to get more info
from the user table.
3. You can use this event to override the user name, User ID, Parent user ID and User Level (if
User ID/Level Security is enabled) for the validated user by the LoginUser() method of the
security class. The arguments of the method are:
function LoginUser($userName = NULL, $userID = NULL, $parentUserID = NULL, $userLevel
= NULL)
If any argument is NULL, the corresponding property will not be affected.
Example 1
Add additional current user info to the global user profile object
function User_Validated(&$rs) {
Profile()->Set("Notes", $rs["Notes"]); // Set additional data to the profile object
Profile()->Save(); // Save to session
}
Example 2
Check if an user password has expired by custom code with Enable password expiry (see Security
Settings) enabled
function User_Validated(&$rs) {
if ($rs["PasswordExpired"] == "Y") { // Assume the user table has a field named
"PasswordExpired" storing if the password has expired
Profile()->setPasswordExpired($rs["Username"]); // Assume the user name field is named
"Username"
return FALSE; // Return FALSE to invalidate the user
}
}
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 10 of 47
UserLevel_Loaded For use with User Level security. (See Security Settings) This event is fired after successful user login and
after the User Level settings are loaded. It is possible to do actions such as changing or adding User
Level permissions. Note: This event is a security class member.
Example 1
// Note: This event is a Security class member, so you can refer to other members of the
Security class directly
function UserLevel_Loaded() {
$this->deleteUserPermission("Sales", "orders", ALLOW_ADD); // The first 2 arguments can also
be array
$this->addUserPermission("Sales", "orders", ALLOW_EDIT); // The first 2 arguments can also
be array
}
Example 2
// Note: This event is a Security class member, so you can refer to other members of the
Security class directly
function UserLevel_Loaded() {
$this->addUserPermission("Manager", "employees", ALLOW_ALL); // The first 2 arguments can
also be array
}
MenuItem_Adding This event is fired for custom menu items before it is added to the menu. The menu item info is passed
to the event as an instance of the cMenuItem object (see below). Return FALSE if you don't want to show
the menu item. If you return TRUE, the menu item will be added to the menu, but it does not mean that
it will be always displayed. A menu item will be displayed only if its Allowed property is TRUE. When the
menu item is passed to this event, the Allowed property is set based on the User Level Security of the
project, you can however change it by setting $Item->Allowed as TRUE or FALSE as needed. Note: This is
a global function.
Example 1
function MenuItem_Adding(&$item) {
//var_dump($Item);
// Return False if menu item not allowed
if ($item->Text == "Download")
return Security()->IsLoggedIn();
return TRUE;
}
Example 2
function MenuItem_Adding(&$item) {
//var_dump($item);
if ($item->Text == "Download")
$item->Icon = "fa-download";
if ($item->Text == "Something")
$item->Label = "<small class=\"label float-right bg-green\">new</small>"; // Label
shows on the right hand side of the menu item (for vertical menu only)
return TRUE;
}
Note If your project is multi-language, the $item->Text will be different for each language, you
may check $item->Name or $item->Url instead. Check the generated ewmenu.php to see the item
names or URLs.
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 11 of 47
Menu_Rendering This event is fired before the menu is rendered. You can manipulate the menu items in this event. The
argument is the menu object. (See Menu Object below.) Note: This is a global function.
Example 1
Add an additional menu item to the menu for logged in users only.
function Menu_Rendering($menu) {
if ($menu->Id == "menu") { // Sidebar menu or change from "menu" to "navbar" for top menu
$menu->addMenuItem(10000, "MyName", "MyMenuText", "MyPage.php", -1, "", IsLoggedIn());
$menu->moveItem("Logout", $menu->Count() - 1); // Move to last
}
}
Example 2
Remove all the default menu items and use your own menu items.
function Menu_Rendering(&$menu) {
if ($menu->Id == "menu") { // Sidebar menu
$menu->Clear(); // Clear all menu items
$menu->addMenuItem(1, "MyName1", "MyMenuText1", "MyPage1.php");
$menu->addMenuItem(2, "MyName2", "MyMenuText2", "MyPage2.php");
}
}
Example 3
function Menu_Rendering(&$menu) {
if ($menu->Id == "menu") { // sidebar menu
$menu->Accordion = FALSE; // Whether to collapse the open menu when expanding another,
default is TRUE
}
}
Menu_Rendered This event is fired after the menu is rendered. You may want to clean up in this event if you have created
something in the Menu_Rendering event. The argument is the menu object. (See Menu Object below.)
Note: This is a global function.
TablePermission_Loading For use with User Level security. (See Security Settings) This event is fired before the user permission for
the table of the current page is loaded. It is possible to do actions such as changing or adding more User
Level permissions to the current user. Note: This event is a security class member.
Note This is an event fired for the current table only. If you change the permissions of the
other tables in this event, there will be no effect. Use the UserLevel_Loaded event if you need to
change permissions of other tables.
Example
Grant another User Level to the user and let the user have permissions of more than one User Level for
the current table.
// Note: This event is a Security class member, so you can refer to other members of the
Security class directly
function TablePermission_Loading() {
if (CurrentUserName() == "nancy")
$this->AddUserLevel("Manager");
}
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 12 of 47
TablePermission_Loaded For use with User Level security. (See Security Settings) This event is fired after the user permission for
the table of the current page is loaded. It is possible to to change the permission by using the
setCanXXX methods of the Security class. Note: This event is a security class member.
Note This is an event fired for the current table only. If you change the permissions of the
other tables in this event, there will be no effect. Use the UserLevel_Loaded event if you need to
change permissions of other tables.
Example
Grant more permissions to the user and let the user have more permissions than his/her User Level
allows for the current table.
// Note: This event is a Security class member, so you can refer to other members of the
Security class directly
function TablePermission_Loaded() {
if (CurrentUserName() == "nancy" && CurrentTable()->TableName == "orders")
$this->setCanEdit(TRUE);
}
UserID_Loading For use with User ID security. (See Security Settings) This event is fired after successful user login and
before loading the User ID and its child User IDs of the current user. These User IDs determine which
records the current user can access. It is possible to do actions such as changing the User ID of the
current user so the user can access records that he/she can access by its original User ID. Note: This
event is a security class member.
Example
Change the user's User ID to his parent user's user ID and let the user access more records (accessible by
the parent user).
// Note: This event is a Security class member, so you can refer to other members of the
Security class directly
function UserID_Loading() {
if (CurrentParentUserID() <> "")
$this->CurrentUserID = CurrentParentUserID();
}
UserID_Loaded For use with User ID security. (See Security Settings) This event is fired after loading the User ID and its
child User IDs of the current user. These User IDs determine which records the current user can access. It
is possible to do actions such as adding or deleting the loaded User IDs for the current user so the user
can access more or less records that he/she can access by its originally loaded User IDs. Note: This
event is a security class member.
Example
Add more User IDs to the user and let the user access more records
// Note: This event is a Security class member, so you can refer to other members of the
Security class directly
function UserID_Loaded() {
if (CurrentUserName() == "nancy")
$this->AddUserName("janet"); // Add User ID by user name
}
User_PasswordExpired This event will be called if the user password is already expired. User information is passed to the event
as argument, you can get user information by $rs["<fieldname>"] where <fieldname> is a field name of
the user table. Note: This event is a security class member.
AuditTrail_Inserting This event will be called before an audit trail record is written. The audit trail information is passed to the
event as argument, you can get the information by $rsnew["<fieldname>"] where <fieldname> is the
audit trail field name. Return False to cancel the insert. Note: This is a global function.
PersonalData_Downloading This event will be called when Use Personal Data Page is enabled and before the user downloads his
personal data. The personal data is passed to the event as an associative array, you can get the
information by $row["<fieldname>"] where <fieldname> is an user table field name. You can also add
additional data to the array so it will also be downloaded by the user. Note: This is a global function.
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 13 of 47
PersonalData_Deleted This event will be called when Use Personal Data Page is enabled and before the user deletes his
personal data. The personal data is passed to the event as an associative array, you can get the
information by $row["<fieldname>"] where <fieldname> is an user table field name. Note: This is a
global function.
Table-Specific -> Common (Note: These events are members of the page class)
Recordset_Selecting This event will be called before selecting records. The argument of the event is the filter (part of the
WHERE clause of the SQL) for selecting records, you can customize the filter to change the records to be
selected.
Example
Add your own filter. Note that the $filter may have value, if you want to add some additional filter,
append your filter to it, not replace it.
function Recordset_Selecting(&$filter) {
AddFilter($filter, "Field1 = 1234"); // Add your own filter expression
}
Recordset_Selected This event will be called after selecting records. Note: The argument is the recordset object (not array).
Recordset_SearchValidated This event will be called after the Form_CustomValidate event and the search criteria is assigned to the
table/field objects. You can modify the search criteria in this event.
This event is a member of the table class. There is no arguments for this event. To change the Quick
Search criteria, change the BasicSearchKeyword and BasicSearchType property of the table object. To
change the Advanced Search criteria, change the AdvancedSearch property (which is an object of the
AdvancedSearch class) of the field object.
Example
function Recordset_SearchValidated() {
$this->MyField1->AdvancedSearch->SearchValue = "your search criteria"; // Search value
}
Recordset_Searching This event will be called before the search criteria is saved for the session. The argument of the event is
the part of WHERE clause built from the Quick/Extended/Advanced search criteria. You can modify the
WHERE clause in this event.
Example
Search a MySQL DATE field for a selected date or within 3 days after the selected date.
function Recordset_Searching(&$filter) {
//die($filter); // Uncomment to view the filter first
$filter = preg_replace('/`MyDateField` = (\'\d{4}-\d{2}-\d{2}\')/', '`MyDateField` >= $1 AND
`MyDateField` < DATE_ADD($1, INTERVAL 3 DAY)', $filter); // Replace part of the filter with your
modified filter
}
Row_Deleting This event will be called before deleting a record. The argument of the event is the record to be deleted
as an array.
Row_Deleted This event will be called after deleting a record. The argument of the event is the record deleted as an
array.
Example
Delete detail records from the detail table after the master record is deleted.
function Row_Deleted(&$rs) {
// Assume ForeignKeyField is of integer type
Execute("DELETE FROM DetailTable WHERE ForeignKeyField=" . $rs["PrimaryKeyField"]);
}
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 14 of 47
Row_Inserting This event will be called before inserting a record. The arguments of the event are the arrays of the old
(if copying record) and new record to be inserted. You can change the values in the $rsnew.
Example
Row_Inserted This event will be called after inserting a record. The arguments of the event are the arrays of the old (if
copying record) and new record just inserted.
Example
Row_Rendering This event will be called before rendering (applying the View/Edit Tag settings) a record.
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 15 of 47
This is an extremely useful event for conditional formatting, you can do a lot of things with this event,
such as changing font color, font styles, row background color, cell background color, etc. by changing
the table or field class properties in the event according to field values.
Note The table class has a RowAttrs property which is an associative array of HTML attributes for
the table row. The field class has CellAttrs, ViewAttrs and EditAttrs for the table cell, View Tag
and Edit Tag of the field respectively. The keys of these arrays must be valid HTML attributes for
the HTML tag, always use lowercase for the keys. The attribute values will be outputted as double
quoted attributes, so if you have double quotes in your values, try to use single quotes if possible,
or use """.
To view the properties of the field class for development or debugging, you can use the PHP's
var_dump function in the server event, e.g.
var_dump($this->RowAttrs);
var_dump($this->Trademark);
var_dump($this->Trademark->CellAttrs);
var_dump($this->Trademark->EditAttrs);
var_dump($this->Trademark->ViewAttrs);
Example
function Row_Rendered() {
// Change the row color in List page by Bootstrap classes
if ($this->Trademark->CurrentValue == 1) // List page only
$this->RowAttrs["class"] = "info";
// Change the table cell color
$pageID = CurrentPageID();
if ($pageID == "list" || $pageID == "view") { // List/View page only
if ($this->Cyl->CurrentValue == 4) {
$this->Cyl->CellAttrs["style"] = "background-color: #ffcccc";
} elseif ($this->Cyl->CurrentValue == 6) {
$this->Cyl->CellAttrs["style"] = "background-color: #ffcc99";
} elseif ($this->Cyl->CurrentValue == 8) {
$this->Cyl->CellAttrs["style"] = "background-color: #ffccff";
}
}
Row_Selecting This event will be called before selecting a record. The argument of the event is the filter (part of the
WHERE clause of the SQL) for selecting the record, you can customize the filter to change the record to
be selected.
Row_Selected This event will be called after selecting a record. The argument is the record selected as an array. The
event is still fired when inserting a new record, but in such case there is no "selected" row and the
argument is an array with all field values as NULL.
Example
function Row_Selected(&$rs) {
if ($this->PageID == "edit") // Edit Page only
$this->MyField->Disabled = ($rs["MyField"] == "xxx"); // Disable a field if the field
value equals some value
}
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 16 of 47
Row_UpdateConflict This event will be called if conflicts is found before updating a record (if Check Conflicts is enabled, see
Table Setup). The arguments of the event are the old record (as array) and new record (as array) to be
updated.
You can use this event to resolve the conflicts according to your own criteria. If you want to ignore
conflicts or you have resolved the conflicts in the event (by setting new values to the argument rsnew)
and want to continue update, return FALSE. Otherwise, return TRUE. By default the event returns TRUE.
Row_Updating This event will be called before updating a record. The arguments of the event are the arrays of the old
and new record to be updated.
Example
Row_Updated This event will be called after updating a record. The arguments of the event are the arrays of the old
and new record updated.
Example
After updating a field in detail table, update a field in the master table.
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 17 of 47
Grid_Inserting For use with Grid-Add for a table and Master/Detail-Add for a detail table, this event will be called
before inserting records. This event has no arguments.
You can use this event to check all records to be inserted. If you want to cancel insert, return FALSE.
Otherwise, return TRUE. By default the event returns TRUE.
Note If you only need to check individual record, there is no need to use this event, simply use
Row_Inserting (see above) which will be called for each row in the grid.
Example
Check all records before inserting. Note that this event is called before Row_Inserting, the field values
are not loaded yet, but you can load them yourself.
function Grid_Inserting() {
$rsnew = $this->GetGridFormValues(); // Get the form values of the new records as an array
of array
//var_dump($rsnew); die(); // Print the records and end the script
$sum = 0;
foreach ($rsnew as $row) // Loop through the new records
$sum += intval($row["Percentage"]);
if ($sum < 100) {
// To cancel, set return value to False
$this->setFailureMessage("The total of percentages must be 100.");
return FALSE;
}
return TRUE;
}
Note Data returned from GetGridFormValues() is read only, do NOT try to change the values. To
change the values, use Row_Inserting (see above) which will be called for each row in the grid.
Grid_Inserted For use with Grid-Add for a table and Master/Detail-Add for a detail table, this event will be called
after inserting all records. The argument of the event ($rsnew) is array of records inserted (retrieved
from database).
For example, you can use this event to update a field in the master table (similar to the example for
Row_Updated above) after Master/Detail-Add.
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 18 of 47
Grid_Updating For use with Grid-Edit for a table and Master/Detail-Edit for a detail table, this event will be called
before updating records. The argument of the event ($rsold) is array of records to be updated (retrieved
from database).
You can use this event to check all records to be updated. If you want to cancel update, return FALSE.
Otherwise, return TRUE. By default the event returns TRUE.
Note If you only need to check individual record, there is no need to use this event, simply use
Row_Updating (see above) which will be called for each row in the grid.
Example
Check all records before updating. Note that this event is called before Row_Updating, the field values
are not loaded yet, but you can load them yourself.
function Grid_Updating($rsold) {
$rsnew = $this->GetGridFormValues(); // Get the form values of the new records as an array
of array
//var_dump($rsnew); die(); // Print the records and end the script
$oldtotal = 0;
foreach ($rsold as $row) // Loop through the old records
$oldtotal += intval($row["Subtotal"]);
$newtotal = 0;
foreach ($rsnew as $row) // Loop through the new records
$newtotal += intval($row["Subtotal"]);
if ($newtotal < $oldtotal) {
// To cancel, set return value to False
$this->setFailureMessage("The new total must be larger than the old total.");
return FALSE;
}
return TRUE;
}
Note Data returned from GetGridFormValues() is read only, do NOT try to change the values. To
change the values, use Row_Updating (see above) which will be called for each row in the grid.
Grid_Updated For use with Grid-Edit for a table and Master/Detail-Edit for a detail table, this event will be called after
updating all records. The argument of the event ($rsold and $rsnew) are array of records before and
after update (retrieved from database).
For example, you can use this event to update a field in the master table (similar to the example for
Row_Updated above) after Master/Detail-Edit.
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 19 of 47
Email_Sending This event is fired before the email notification is sent. You can customize the email content using this
event. Email_Sending event has the following parameters:
$email - the email object instance which contain all the information about the email to be sent. It is an
instance of the Email class (see below).
$args - an array which contains additional information.
If Add, the new record in the format of array can be access by $args["rsnew"].
If Copy, the old record in the format of array can be access by $args["rsold"].
If Edit/Update, the old data of the records in the format of array can be access by $args["rsold"], the
new data of the records in the format of array can be access by $args["rsnew"].
If Register, the new record in the format of array can be access by $args["rs"].
$rsnew = $args["rsnew"];
$myValue = $rsnew["MyField"];
or
$myValue = $args["rsnew"]["MyField"];
Return FALSE in the event if you want to cancel the email sending.
If Grid-Add/Edit or Update page, there are more than one records, the arguments are array of array.
Example
Assume there is an email field in the record, and you want to change the recipient to the value of that
field.
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 20 of 47
Lookup_Selecting This event is fired before building the SQL for selecting records from the lookup table. You can use this
event to change the filters.
In the event, the field name, Lookup object and filter for the lookup can be viewed by:
$fld->Lookup is an object. To change the lookup SQL, you can modify the following properties of the
Lookup object:
Example 1
Example 2
Example 3
Example 4
Example 5
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 21 of 47
UserID_Filtering For use with User ID security. (See Security Settings) This event is fired before adding the User ID filter to
the WHERE clause of the table. It is possible to modify, replace or add filter so the user can access more
or less records that he/she can access by its originally loaded User IDs.
Example
Assume you have 2 User ID fields in the current table and in the user table, and you want to filter by
both User ID fields.
function UserID_Filtering(&$filter) {
AddFilter($filter, "MyUserIDField2 = " . CurrentUserInfo("MyUserIDField2InUserTable")); //
Assume the field is of integer type
}
Page_Render This event will be called before outputting HTML for the page. You can use this event to make some last
minute changes to the page before it is outputted.
Page_DataRendering This event will be called after the header.php is included. You can use this event to add content at the
top of page content.
Page_DataRendered This event will be called before the footer.php is included. You can use this event to add content at the
bottom of page content.
Page_Redirecting This event will be called before redirecting to other page. The argument is the URL to be redirected to.
By default after inserting a record user is redirected back to the List page. You can change that by using
Return Page (see Table Setup). However, If you want to change by code, you can also use this event.
Message_Showing This event is fired before the message stored in the session variable is shown.
The first argument $msg is the message to be shown, the second argument $type is the type of the
message, possible values of type are: "" (empty string), "success", "failure", and "warning".
Example
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 22 of 47
Form_CustomValidate This event is fired after the normal form validation. You can use this event to do your own custom
validation. In general, the form data can be accessed by $this-><Field>->FormValue (e.g.
$this->HP->FormValue). Alternatively, you can get all the form values in an array first, e.g.
$rs = $this->GetFieldValues("FormValue");
An argument $customError is passed to the event, you can add your error message and return FALSE if
the form values do not pass your validation.
Example
function Form_CustomValidate(&$customError) {
$rs = $this->GetFieldValues("FormValue"); // Get the form values as array
if (intval($rs["Qty"]) % 10 <> 0) {
// Return error message in $customError
$customError = "Order quantity must be multiples of 10.";
return FALSE;
}
return TRUE;
}
Note If you use this server event, make sure you have enabled server-side validation, see
Validation in PHP Settings.
Page_Render This event will be called before outputting HTML for the page. You can use this event to make some last
minute changes to the page before it is outputted.
Page_DataRendering This event will be called after the header.php is included. You can use this event to add content at the
top of page content.
Page_DataRendered This event will be called before the footer.php is included. You can use this event to add content at the
bottom of page content.
Message_Showing This event is fired before the message stored in the session variable is shown. You can use this event to
change the message which is passed to the event as argument.
Page_Redirecting This event will be called before redirecting to other page. Event argument is the URL to be redirected to.
By default after deleting record(s) user is redirected back to the List page. You can change that using this
event.
Page_Render This event will be called before outputting HTML for the page. You can use this event to make some last
minute changes to the page before it is outputted.
Page_DataRendering This event will be called after the header.php is included. You can use this event to add content at the
top of page content.
Page_DataRendered This event will be called before the footer.php is included. You can use this event to add content at the
bottom of page content.
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 23 of 47
Message_Showing This event is fired before the message stored in the session variable is shown. You can use this event to
change the message which is passed to the event as argument.
Page_Redirecting This event will be called before redirecting to other page. Event argument is the URL to be redirected to.
By default after updating a record user is redirected back to the List page. You can change that by using
Return Page (see Table Setup). However, If you want to change by code, you can use this event.
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 24 of 47
Note The export links are stored as a ListOptions object (also see ListOptions_Load,
ListOptions_Rendering and ListOptions_Rendered event below), you can manipulate the links in
the same way. The defaut names of the options are:
• print
• html
• excel
• word
• xml
• csv
• pdf
• email
Example 1
function Page_Load() {
$item = @$this->ExportOptions->Items["pdf"];
if ($item)
$item->Visible = FALSE;
}
Example 2
function Page_Load() {
$item = &$this->ExportOptions->add("MyName");
$item->Body = "<a href='MyURL'>My Link</a>";
}
Example 3
function Page_Load() {
$this->CustomActions["star"] = "Add Star"; // Where "star" is the id and "Add Star" is the
caption of the custom action
}
Adding a custom action by its name and caption is a actually a short form of
and is supported for backward compatibility only. Use the ListAction class so you have more options for
the custom action. The constructor of ListAction class is
$select is either ACTION_MULTIPLE (submit the selected records) or ACTION_SINGLE (submit the current
record only).
$success is the name of JavaScript callback function, if any. You can place your callback function in client
side Global Code section (see below).
Note To process the action, you also need to write a handler with Row_CustomAction server
event (see below).
Example 4
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 25 of 47
function Page_Load() {
$this->CustomActions["star"] = new ListAction("star", "Add Star", IsLoggedIn(), ACTION_AJAX,
ACTION_MULTIPLE, "Add Star to selected records?", "fa fa-star ew-icon");
}
Note To process the action, you also need to write a handler with Row_CustomAction server
event (see below).
Example 5
When Custom Templates (see Custom Templates) is used, they will be used for export to
Word/Excel/PDF/Email (not including PhpSpreadsheet and PHPWord) by default. You can however
change it.
function Page_Load() {
$item = @$this->ExportOptions->Items["excel"];
if ($item)
$item->Body = $this->getExportTag("excel", FALSE); // Do not use Custom Templates for
export to Excel
}
Page_Render This event will be called before outputting HTML for the page. You can use this event to make some last
minute changes to the page before it is outputted.
Page_DataRendering This event will be called after the header.php is included. You can use this event to add content before
the main table.
Example
function Page_DataRendering() {
$this->MyField->Visible = FALSE; // Hide a field named "MyField"
}
Page_DataRendered This event will be called before the footer.php is included. You can use this event to add content after
the main table.
Page_Redirecting This event will be called before redirecting to other page. Event argument is the URL to be redirected to.
Message_Showing This event is fired before the message stored in the session variable is shown. You can use this event to
change the message which is passed to the event as argument.
Form_CustomValidate This event is fired after the normal form validation. You can use this event to do your own custom
validation. See description of Form_CustomValidate for Add/Copy page above.
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 26 of 47
ListOptions_Load This event will be called before the main table is rendered. Use this event to modify the non data
columns of the main table (i.e. the links and the checkbox for each record). You can modify these
columns or add your own columns using this event. You can get a column by name using
$this->ListOptions->Item["name"].
Note The following predefined names are reserved, do not use them for your own columns. These
names are case-sensitive and are in lowercase except for the detail table names.
• checkbox
• view
• copy
• delete
• edit
• detail_<DetailTable> - Detail table column
• details - the Multiple Master/Detail column
• preview - column for preview row of the Detail Preview extension (for registered users)
only
• sequence - column for sequence number
• button - column for button group or button dropdown
Example 1
function ListOptions_Load() {
$item = &$this->ListOptions->Add("new");
$item->Header = "MyCaption"; // Set the column header (for List page)
$item->OnLeft = TRUE; // Link on left
$item->MoveTo(0); // Move the column to the specified index
}
Note If you have enabled Use buttons as links and/or Use button dropdown for links (see PHP
Settings), note that the feature will hide the list options and try to move hyperlinks to the button
group or button dropdown. If your Body property (see below) is not hyperlink(s), it cannot be
shown in the button group or button dropdown, you should remove your list option from the
button group or button dropdown by adding, e.g.
$item->ShowInButtonGroup = FALSE;
and/or
$item->ShowInDropDown = FALSE;
Example 2
function ListOptions_Load() {
$this->ListOptions->Items["view"]->Visible = FALSE;
}
Example 3
Hide a detail table named "MyDetailTable" in Preview Row or Overlay (requires Detail Preview extension
which is for registered users only)
function ListOptions_Load() {
$this->DetailPages->Items["MyDetailTable"]->Visible = FALSE;
}
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 27 of 47
ListOptions_Rendering This event will be called before list options are rendered. To access field object of the current row, you
can use $this-><Field>-><Property> (e.g. $this->HP->CurrentValue).
Note Do NOT try to show/hide a column dynamically by setting the Visible property of the list
option in this event. If the column is visible in one row but invisible in another, the table will be
malformed.
Example 1
function ListOptions_Rendering() {
$GLOBALS["orderdetails_grid"]->DetailAdd = (...condition...); // Set to TRUE or FALSE
conditionally
$GLOBALS["orderdetails_grid"]->DetailEdit = (...condition...); // Set to TRUE or FALSE
conditionally
$GLOBALS["orderdetails_grid"]->DetailView = (...condition...); // Set to TRUE or FALSE
conditionally
}
Example 2
Append a CSS class to all cells (including header/footer cell) of a field in the List page
function ListOptions_Rendering() {
$this->Category->AddClass("some-class"); // Add CSS class to the field
}
Notes
1. The AddClass() method add class to all cells including those in table header and footer. Do
not use this method if you want to add class for the current row only.
2. Use this example carefully if your List page supports Inline/Grid-Add/Copy/Edit. If a field is
only visible in large screen, it cannot be updated in smaller screens.
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 28 of 47
ListOptions_Rendered This event will be called after list options are rendered. Use this event to modify content of the non data
columns for the record. To access field object of the current row, you can use $this-
><Field>-><Property> (e.g. $this->HP->CurrentValue).
Note Do NOT try to show/hide a column dynamically by setting the Visible property of the list
option in this event. If the column is visible in one row but invisible in another, the table will be
malformed. If you want to hide the content dynamically, you can set the Body property as empty
string.
Example 1
Set the content of the new column dynamically based on a field value.
function ListOptions_Rendered() {
if ($this->MyField->CurrentValue == "xxx") {
$this->ListOptions->Items["new"]->Body = "yyy";
} else {
$this->ListOptions->Items["new"]->Clear(); // Set Body = ""
}
}
Example 2
function ListOptions_Rendered() {
$this->ListOptions->Items["new"]->Body = "<a href=\"#\" onclick=\"return ew.submitAction
(event, {action: 'star', method: 'ajax', msg: 'Add star?', key: " . $this->KeyToJson(TRUE) .
"});\">Add Star</a>";
}
Note To process the action, you also need to write a handler with Row_CustomAction server
event (see below).
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 29 of 47
Row_CustomAction If you have used Page_Load server event (see above) to add your custom action to the List page, the
page will show the checkbox column for users to select records (similar to Multi-Update and Mulit-
Delete). When user clicks the custom action link or button, the page will post back to itself and this event
will be fired (after Page_Load and before Page_Render) for each selected row to process the custom
action.
Return TRUE to proceed to next record or return FALSE to abort custom action.
Example
Update the status of the selected records, assuming the table has a field named "Starred" for storing the
status, and the primary key is an integer field names "ID".
Note If you cancel the action by returning FALSE in the event, you can use the setFailureMessage
() method to set your message. However, note that if the event returns FALSE, subsequent rows
will not be processed and the database changes for previous rows will be rolled back (if your
database supports transaction). So if you just want to cancel action for a row without affecting
other rows, the event should still return TRUE and use setSuccessMessage() method to set your
message.
Page_Exporting This event will be called before the page is exported. You can use this event to add your additional code
to the beginning of file to be exported. Return FALSE to skip default export and use Row_Export event
(see below). Return TRUE to use default export and skip Row_Export event. Check $this->Export for the
export type (e.g. "excel", "word"). The content of the export document is $this->ExportDoc->Text
(except PhpSpreadsheet/PHPWord).
Note If Custom Templates is used (see Custom Templates), this event may be overridden. You
can disable using Custom Templates for report, see example for Page_Load above.
Example
Add a title to the export document and use custom export if export to Excel (not PhpSpreadsheet)
function Page_Exporting() {
if ($this->Export == "excel") {
$this->ExportDoc->Text = "<p>My Title</p>"; // Add a title
return FALSE; // Return FALSE to skip default export and use Row_Export event
}
return TRUE; // Return TRUE to use default export and skip Row_Export event
}
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 30 of 47
Row_Export If you return FALSE in Page_Exporting event (see above), this event will be called when a row is
exported for you to export in your own code.
The argument ($rs) is an array of the record to be exported. The values in $rs are unformatted database
values. If you want to export formatted values, use $this->MyField->ViewValue.
Notes
1. If you return TRUE in Page_Exporting event (see above), default export will be used and this
event will NOT be called.
2. If Custom Templates is used (see Custom Templates), this event may be overridden. You can
disable using Custom Templates for report, see example for Page_Load above.
Example
function Row_Export($rs) {
if ($this->Export == "excel")
$this->ExportDoc->Text .= "<div>" . $this->MyField->ViewValue . "</div>"; // Build HTML
with field value: $rs["MyField"] or $this->MyField->ViewValue
}
Page_Exported This event will be called after the page is exported. You can use this event to add your additional code to
the end of the file to be exported.
Note If Custom Templates is used (see Custom Templates), this event may be overridden. You
can disable using Custom Templates for report, see example for Page_Load above.
Example
function Page_Exported() {
if ($this->Export == "excel")
$this->ExportDoc->Text .= "my footer"; // Add a footer
//die($this->ExportDoc->Text); // View the whole export document for debugging
}
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 31 of 47
Page_Importing This server event allows you to modify the Import options before the import process begins. The first
argument is the data reader and the second argument is an array containing the import options. You can
also return FALSE to skip the import.
The options (accessed by $options["<value>"]) you can change during Page_Importing are:
maxExecutionTime - Maximum execution time for import
activeSheet - Active spreadsheet for import (default is 0, zero-based)
headerRowNumber - Header row number (default is 0, zero-based)
headers - Header array (default is empty array)
offset - Offset to start import (default is 0, zero-based)
limit - Number of records to import (default is 0, which means all records)
inputEncoding - Input encoding for data (CSV only)
delimiter - Delimiter for data (CSV only)
enclosure - Quote character for data (CSV only)
Example 1
Example 2
The spreadsheet contains pure data only. Supply the header manually.
Example 3
Row_Import This server event is executed before a record is imported. The first argument is an array containing the
data to be imported and the second argument is an integer containing the current import record count.
You can return FALSE to skip the import.
Example 1
Example 2
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 32 of 47
Page_Imported This server event is executed after import is completed. The first argument is the data reader and the
second argument is an array containing the import results.
Example
Page_Render This event will be called before outputting HTML for the page. You can use this event to make some last
minute changes to the page before it is outputted.
Page_DataRendering This event will be called after the header.php is included. You can use this event to add content at the
top of page content.
Page_DataRendered This event will be called before the footer.php is included. You can use this event to add content at the
bottom of page content.
Page_Redirecting This event will be called before redirecting to other page. Event argument is the URL to be redirected to.
By default after updating records user is redirected back to the List page. You can change that by using
this event.
Message_Showing This event is fired before the message stored in the session variable is shown. You can use this event to
change the message which is passed to the event as argument.
Form_CustomValidate This event is fired after the normal form validation. You can use this event to do your own custom
validation. See description of Form_CustomValidate for Add/Copy page above.
Page_Render This event will be called before outputting HTML for the page. You can use this event to make some last
minute changes to the page before it is outputted.
Page_DataRendering This event will be called after the header.php is included. You can use this event to add content at the
top of page content.
Page_DataRendered This event will be called before the footer.php is included. You can use this event to add content at the
bottom of page content.
Page_Redirecting This event will be called before redirecting to other page. Event argument is the URL to be redirected to.
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 33 of 47
Message_Showing This event is fired before the message stored in the session variable is shown. You can use this event to
change the message which is passed to the event as argument.
Page_Render This event will be called before outputting HTML for the page. You can use this event to make some last
minute changes to the page before it is outputted.
Page_DataRendering This event will be called after the header.php is included. You can use this event to add content at the
top of page content.
Page_DataRendered This event will be called before the footer.php is included. You can use this event to add content at the
bottom of page content.
Page_Redirecting This event will be called before redirecting to other page. Event argument is the URL to be redirected to.
By default user is redirected to the List page after the search criteria is processed. You can change that
by using this event.
Message_Showing This event is fired before the message stored in the session variable is shown. You can use this event to
change the message which is passed to the event as argument.
Form_CustomValidate This event is fired after the normal form validation. You can use this event to do your own custom
validation. See description of Form_CustomValidate for Add/Copy page above.
Page_Render This event will be called before outputting HTML for the page. You can use this event to make some last
minute changes to the page before it is outputted.
Page_DataRendering This event will be called after the header.php is included. You can use this event to add content at the
top of page content.
Page_DataRendered This event will be called before the footer.php is included. You can use this event to add content at the
bottom of page content.
Page_Redirecting This event will be called before redirecting to other page. Event argument is the URL to be redirected to.
Message_Showing This event is fired before the message stored in the session variable is shown. You can use this event to
change the message which is passed to the event as argument.
Page_Exporting This event will be called before the page is exported. You can use this event to add your additional code
to the beginning of file to be exported. Return FALSE to skip default export and use Row_Export event
(see below). Return TRUE to use default export and skip Row_Export event. Check $this->Export for the
export type (e.g. "excel", "word"). The content of the export document is $this->ExportDoc->Text.
Note If Custom Templates is used (see Custom Templates), this event may be overridden. You
can disable using Custom Templates for report, see example for Page_Load above.
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 34 of 47
Row_Export If you return FALSE in Page_Exporting event (see above), this event will be called when a row is
exported for you to export in your own code. The argument ($rs) is an array of the record to be
exported. The values are unformatted database values. If you want to export formatted values, use
$this->MyField->ViewValue.
Note If Custom Templates is used (see Custom Templates), this event may be overridden. You
can disable using Custom Templates for report, see example for Page_Load above.
Page_Exported This event will be called after the page is exported. You can use this event to add your additional code to
the end of the file to be exported.
Note If Custom Templates is used (see Custom Templates), this event may be overridden. You
can disable using Custom Templates for report, see example for Page_Load above.
Page_Render This event will be called before outputting HTML for the page. You can use this event to make some last
minute changes to the page before it is outputted.
Page_DataRendering This event will be called before the page content is outputted. You can use this event to add content at
the top of page content.
Page_DataRendered This event will be called after the page content is outputted. You can use this event to add content at the
bottom of page content.
Page_Redirecting This event will be called before redirecting to other page. Event argument is the URL to be redirected to.
Message_Showing This event is fired before the message stored in the session variable is shown. You can use this event to
change the message which is passed to the event as argument.
Page_Redirecting This event will be called before redirecting to other page. Event argument is the URL to be redirected to.
By default user is redirected to the default page (e.g. index.php) after successful login. You can change
that by using this event.
Page_Render This event will be called before outputting HTML for the page. You can use this event to make some last
minute changes to the page before it is outputted.
Page_DataRendering This event will be called after the header.php is included. You can use this event to add content at the
top of page content.
Page_DataRendered This event will be called before the footer.php is included. You can use this event to add content at the
bottom of page content.
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 35 of 47
Page_Redirecting This event will be called before redirecting to other page. Event argument is the URL to be redirected to.
By default user is redirected to the default page (e.g. index.php) after successful login. You can change
that by using this event.
Message_Showing This event is fired before the message stored in the session variable is shown. You can use this event to
change the message which is passed to the event as argument.
User_LoggingIn This event will be called before validating the username and password.
Form_CustomValidate This event is fired after the normal form validation. You can use this event to do your own custom
validation. Inspect the HTML source of the page in your browser to view the form element names.
An argument $customError is passed to the event, you can add your error message and return FALSE if
the form values do not pass your validation.
Page_Redirecting This event will be called before redirecting to other page. Event argument is the URL to be redirected to.
By default user is redirected to the default page (e.g. index.php) after successful login. You can change
that by using this event.
Page_Render This event will be called before outputting HTML for the page. You can use this event to make some last
minute changes to the page before it is outputted.
Page_DataRendering This event will be called after the header.php is included. You can use this event to add content at the
top of page content.
Page_DataRendered This event will be called before the footer.php is included. You can use this event to add content at the
bottom of page content.
Page_Redirecting This event will be called before redirecting to other page. Event argument is the URL to be redirected to.
By default user is redirected to the default page (e.g. index.php) after successful login. You can change
that by using this event.
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 36 of 47
Email_Sending This event is fired before the email notification is sent. You can customize the email content using this
event. Email_Sending event has the following parameters:
$email - the email object instance which contain all the information about the email to be sent. It is an
instance of the Email class (see below).
$args - an array which contains additional information. For registration page, the new record in the data
type of a recordset can be accessed by $args["rs"].
Return FALSE in the event if you want to cancel the email sending.
Message_Showing This event is fired before the message stored in the session variable is shown. You can use this event to
change the message which is passed to the event as argument.
Form_CustomValidate This event is fired after the normal form validation. You can use this event to do your own custom
validation. See description of Form_CustomValidate for Add/Copy page above.
User_Registered This event is fired after successful registration of a new user. Argument is a recordset of the new record
in the user table.
User_Activated This event is fired after activating a new user (if user activation is required, see Security Settings).
Argument is a recordset of the new record in the user table.
Page_Render This event will be called before outputting HTML for the page. You can use this event to make some last
minute changes to the page before it is outputted.
Page_DataRendering This event will be called after the header.php is included. You can use this event to add content at the
top of page content.
Page_DataRendered This event will be called before the footer.php is included. You can use this event to add content at the
bottom of page content.
Page_Redirecting This event will be called before redirecting to other page. Event argument is the URL to be redirected to.
By default user is redirected to the default page (e.g. index.php) after successful login. You can change
that by using this event.
Email_Sending This event is fired before the email notification is sent. You can customize the email content using this
event. Email_Sending event has the following parameters:
$email - the email object instance which contain all the information about the email to be sent. It is an
instance of the Email class (see below).
$args - an array containing additional information. For Change Password page, the old data of the
records in the data type of recordset can be accessed by $args["rsold"], the new data of the records in
the data type of recordset can be accessed by $args["rsnew"].
Return FALSE in the event if you want to cancel the email sending.
Message_Showing This event is fired before the message stored in the session variable is shown. You can use this event to
change the message which is passed to the event as argument.
Form_CustomValidate This event is fired after the normal form validation. You can use this event to do your own custom
validation. Inspect the HTML source of the page in your browser to view the form element names.
An argument $customError is passed to the event, you can add your error message and return FALSE if
the form values do not pass your validation.
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 37 of 47
Page_Render This event will be called before outputting HTML for the page. You can use this event to make some last
minute changes to the page before it is outputted.
Page_DataRendering This event will be called after the header.php is included. You can use this event to add content at the
top of page content.
Page_DataRendered This event will be called before the footer.php is included. You can use this event to add content at the
bottom of page content.
Page_Redirecting This event will be called before redirecting to other page. Event argument is the URL to be redirected to.
By default user is redirected to the login page after successful login. You can change that by using this
event.
Email_Sending This event is fired before the email notification is sent. You can customize the email content using this
event. Email_Sending event has the following parameters:
$email - the email object instance which contain all the information about the email to be sent. It is an
instance of the Email class (see below).
$args - an array containing additional information. For Password Recovery Page, the old data of the
records in the data type of recordset can be accessed by $args["rs"].
Return FALSE in the event if you want to cancel the email sending.
Message_Showing This event is fired before the message stored in the session variable is shown. You can use this event to
change the message which is passed to the event as argument.
Form_CustomValidate This event is fired after the normal form validation. You can use this event to do your own custom
validation. Inspect the HTML source of the page in your browser to view the form element names.
An argument $customError is passed to the event, you can add your error message and return FALSE if
the form values do not pass your validation.
User_RecoverPassword This event is fired after the password is recovered. Argument is a recordset of the user's record in the
user table.
Client Scripts
In general, each page has two blocks of JavaScript:
Client Script - the first block of JavaScript to be included at the beginning of the page, you can put your JavaScript variables and
functions there. The View Tag (for display) and Edit Tag (for input) of the fields supports Custom Attributes (See Field Setup) so you can
add your own attributes to work with your own JavaScript included here.
Startup Script - the second block of JavaScript to be included at the end of the page, you can put code here to "start up" your
JavaScript.
Note In the following table, the <fieldname> in code represents the field variable name. In general, if the field name is
alphanumeric, field variable name is same as the field name. Otherwise, spaces are replaced by underscores, and other non
alphanumeric characters are replaced by their hexadecimal string representation of their unicode value. If the variable is a reserved
word or starts with a digit, it will be prepended with an underscore. If in doubt, always inspect HTML source in your browser to
check the actual id, name, and other attributes of the elements.
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 38 of 47
Client Script The script will be placed in the header and therefore included in all pages with header.
Note This event is NOT related to the No header/footer setting in the Generate form (see Generate
Settings). Even if No header/footer is enabled, this event will also be fired.
Example
Set div.content-wrapper and footer min-width if advanced setting "Reset layout height" (see Advanced
Settings) is disabled
Startup Script The script will be placed in the footer and therefore included in all pages with footer. This is a very useful event
which is fired for all pages with footer, you can almost do everything by changing the document DOM.
Note This event is NOT related to the No header/footer setting in the Generate form (see Generate
Settings). Even if No header/footer is enabled, this event will also be fired.
Global Code JavaScript code to be included in all pages with header. This may contain your global constants, variables and
functions.
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 39 of 47
Client Script The script will be placed after the header. This may contain your JavaScript variables and functions for the
page. You can also use this event to subscribe JavaScript events.
Example 1
currentForm.multiPage.set({
//lastPageSubmit: true, // Enable submit button for the last page only
//hideDisabledButton: true, // Hide disabled submit button
//hideInactivePages: true, // Hide inactive pages
//hideTabs: true, // Hide all tabs
//showPagerBottom: true, // Show pager at bottom
//pagerTemplate: '<nav><ul class="pager"><li class="previous ew-prev"><a href="#"><span
class="icon-prev"></span> {Prev}</a></li><li class="next ew-next"><a href="#">{Next} <span
class="icon-next"></span></a></li></ul></nav>' // Pager template
lockTabs: true,// Set inactive tabs as disabled
showPagerTop: true // Show pager at top
});
Note The argument of the Set() method is a JavaScript object, if you modify above example, make sure
that the syntax is correct and that the last property value does not have a trailing comma.
Example 2
Subscribe the jQuery ajaxSend event before an Ajax request is sent (e.g. "updateoption", "autosuggest",
"autofill")
Example 3
Subscribe the "updatedone" event for Dynamic Selection Lists. The event fires after options of a child field is
updated.
Example 4
Subscribe the "create.editor" event for the field named "MyField" to change configuration of the HTML editors.
The event fires before the HTML editor is created.
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 40 of 47
Startup Script The script will be placed before the footer. This is a very useful event which you can almost do everything by
changing the document DOM.
PHPMaker provides a jQuery plugin .fields() for you to easily get/set the form values in client side events
such as Startup Script and Form_CustomValidate (see below)
$row = $(this).fields(); // return an object of all fields, each property is a jQuery object of the
input element(s) of a field
$field = $row["<fieldname>"]; // get jQuery object of the input element(s) of a field
You can also get the jQuery object for a field directly,
The jQuery object of the field is the jQuery object of the input element of the field. (Note that if Edit Tag of the
field is CHECKBOX or RADIO, the jQuery object may contain more than one elements.)
For example, if the page is an Edit page and the field is named "Field1" and it is a textbox, $(this).fields
("Field1") is equivalent to $("#x_Field1"). The advantages of using .fields() plugin is that the returned
jQuery object has the following additional methods:
.value .value() get field value, .value(value) set the field value.
([value])
Note This method is NOT the same as jQuery's .val() method. This method takes other
features (e.g. HTML editor, AutoSuggest) into consideration.
.visible .visible() get the visibility of the field, .visible(value) set the visibility of the field. The value
([value]) should be a boolean value.
Note
1. This method shows/hides the row of the field (i.e. the <tr> or the <div>), NOT
just the input element(s) of the field itself in Add/Edit page.
2. The setter is NOT the same as jQuery's .toggle() method.
.readonly Get/Set the readonly attribute of the input element. The value should be a Boolean value.
(value)
Note For <input type="text"> and <textarea> only.
.disabled Get/Set the disabled attribute of the input element. The value should be a Boolean value.
(value)
Note A disabled control's value is NOT submitted with the form. Use this carefully in
Add/Edit page or the field may be updated with an empty value.
.row() Get the jQuery object of the row (<tr> or <div>) of the field.
Notes
1. If Add/Edit page, the row is the <tr> or the <div> of the field.
2. If Grid page, the row is the <tr> of the record.
.toNumber() Get the input value as a JavaScript Number (by default the input value is string).
.toDate() Get the input value as a moment object (by default the input value is string).
.toJsDate() Get the input value as a JavaScript Date object (by default the input value is string).
Example 1
Add onchange event to the field named "Field1" in Add/Edit page to change other fields by jQuery
plugin .fields()
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 41 of 47
Example 2
Add onclick event to the field named "Field2" which uses CHECKBOX as Edit Tag.
Example 3
Add onchange event to the field named "Field1" in Grid-Add/Edit page to change other fields by jQuery
plugin .fields()
Example 4
$(function() {
currentForm.multiPage.togglePage(2, false); // Hide the 2nd page
});
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 42 of 47
Form_CustomValidate This event is fired after the normal form validation. You can use this event to do your own custom validation.
Note: This function is a member of the JavaScript page class.
Note If you use this client side event, make sure you have enabled client-side validation, see Validation
in PHP Settings.
The HTML form object can be accessed by the parameter fobj. You can also use the jQuery plugin .fields() in
this event.
Example 1
Example 2
Example 3
Form_CustomValidate This event is fired after the normal form validation. You can use this event to do your own custom validation.
The form object can be accessed by the parameter fobj. Return false if the form values do not pass your
validation.
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 43 of 47
Form_CustomValidate This event is fired after the normal form validation. You can use this event to do your own custom validation.
Return false if the form values do not pass your validation.
Note that the form element names are different in Inline-Add/Copy/Edit or Grid-Add/Edit mode of List page.
They are named as "x0_<fieldname>" in Inline-Add/Copy, as "x1_<fieldname>" in Inline-Edit mode, and as
"x1_<fieldname>", "x2_<fieldname>", etc. in Grid-Add/Edit since there are multiple rows. Inspect the elements
in your browser to check the actual form element names.
Note Form_CustomValidate is fired for EVERY row in the grid. You can also use the jQuery
plugin .fields() (see above) to manipulate the fields, but remember that the plugin return field(s) of the
CURRENT row only. If you need to access fields in other rows, either use fobj.elements or jQuery with
CSS selectors.
Form_CustomValidate This event is fired after the normal form validation. You can use this event to do your own custom validation.
The form object can be accessed by the parameter fobj. Return false if the form values do not pass your
validation.
Form_CustomValidate This event is fired after the normal form validation. You can use this event to do your own custom validation.
The form object can be accessed by the parameter fobj. Return false if the form values do not pass your
validation.
Form_CustomValidate This event is fired after the normal form validation. You can use this event to do your own custom validation.
The form object can be accessed by the parameter fobj. Return false if the form values do not pass your
validation.
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 44 of 47
Form_CustomValidate This event is fired after the normal form validation. You can use this event to do your own custom validation.
The form object can be accessed by the parameter fobj. Return false if the form values do not pass your
validation.
Form_CustomValidate This event is fired after the normal form validation. You can use this event to do your own custom validation.
The form object can be accessed by the parameter fobj. Return false if the form values do not pass your
validation.
Form_CustomValidate This event is fired after the normal form validation. You can use this event to do your own custom validation.
The form object can be accessed by the parameter fobj. Return false if the form values do not pass your
validation.
Note It is recommended that you develop your server event and client scripts in the generated script so you can edit and test it
immediately. When you finish your custom script, copy it to PHPMaker custom script editor and save it.
Page Object
The Page object is generated for most pages. You can access the object properties using the -> notation (e.g. CurrentPage()->PageID).
The page class inherits from the table class generated for each table. The methods and properties of the page class varies with page, for
the complete list of methods and properties, please refer to the generated page class in the generated scripts and the class <Table>
(e.g. Cars) in the generated file "<Table>.php".
Field Object
A Field object is generated for each field in a table. For example, the "Trademark" object is generated for the "Trademark" field in the
"Cars" table. You can access the object properties using the -> notation (e.g. CurrentPage()->Trademark->CurrentValue). For the complete
list of methods and properties, please refer to the class DbField in the generated file "phpfn*.php".
Security Object
The Security object is used to store the current Advanced Security settings. Please refer to the class AdvancedSecurity in the generated
file "phpfn*.php" for the complete list of methods and properties.
Email Object
The Email object contains the required information of the email to be sent, the instance of the object will be passed to the
Email_Sending events as argument and let you modify the email. Please refer to the class Email in the generated file "phpfn*.php" for
the complete list of methods and properties.
Menu Object
The Menu object contains all information of a menu, the instance of the menu will be passed to the Menu_Rendering and
Menu_Rendered events as argument and let you work with the menu. Please refer to the class Menu in the generated file "phpfn*.php"
for the complete list of methods and properties.
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 45 of 47
MenuItem Object
The MenuItem object contains all information of the menu item, the instance of the menu item will be passed to the MenuItem_Adding
events as argument and let you work with the menu item. Please refer to the class MenuItem in the generated file "phpfn*.php" for the
complete list of methods and properties.
ListOpions Object
The ListOptions object contains all information of the non data columns in the main table of the List page. Please refer to the class
ListOptions in the generated file "phpfn*.php" for the complete list of methods and properties.
ExportOpions Object
The ExportOptions object contains all information of the export links in the List page. It is also an instance of the class ListOptions.
Please refer to the class ListOptions in the generated file "phpfn*.php" for the complete list of methods and properties.
Language Object
The language Object lets you retrieve a phrase of the active language during runtime. The phrase can be retrieved in the generated
scripts using methods such as phrase(), tablePhrase() and fieldPhrase(). Please refer to the class Language in the generated file
"phpfn*.php" for the complete list of methods and properties.
Breadcrumb Object
The Breadcrumb object contains all information of the breadcrumb at the top of page. Please refer to the class Breadcrumb in the
generated file "phpfn*.php" for the complete list of methods and properties.
There are other objects in the generated code, please refer to the source code of the "phpfn*.php" in template or generated scripts.
Notes
1. In the following table, the argument $dbname or $tablename or $fieldname is the database/table/field variable name. It is
case-sensitive. In general, if the name is alphanumeric, the variable name is same as the name. Otherwise, spaces are replaced
by underscores, and other non alphanumeric characters are replaced by their hexadecimal string representation of their
unicode value. If the variable is a reserved word, it will be prepended with an underscore. If you use databases with the same
name, check the database variable name in the Add Linked Table form, see Linked Tables.
2. If MS Access, the $dbname is the file name of the database without the extension. If Oracle, the $dbname is the schema
name.
3. Argument in square brackets means that the argument is optional.
4. If $dbname is not specified, the database of the project is assumed. If $dbname is specified, the specified database of Linked
Tables is used.
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 46 of 47
Route([$i]) Get the nth (0-based) route value. For use $value = Route(1);
with API and URL Rewrite enabled only. If
$i unspecified, all route values are returned as
array.
Profile() Get the global user profile object Profile()->Set("xxx", "yyy"); // set a
value
Profile()->Save(); // save to session
Profile()->Get("xxx"); // get the value
in other pages
CurrentUserID() For used with User ID Security (see Security $userid = CurrentUserID();
Settings). Get current User ID.
CurrentUserLevel() For used with User Level Security (see Security $levelid = CurrentUserLevel();
Settings). Get current user's User Level ID
(integer). (Note: NOT current user's permission
as integer.)
CurrentUserInfo($fieldname) For used with Advanced Security (see Security $email = CurrentUserInfo("email");
Settings). Get current user's info from the user
table. The argument is the field name in the
user table.
CurrentPageID() Get current page ID. A page ID identifies the if (CurrentPageID() == "add") {
page type, it can be "list", "view", "add", "edit", ...your code...
}
"delete", "search", etc.
Page([$tablename]) Get page object of another table in the page, $value = Page("MyMasterTable")
e.g. the page object of the master table or ->MyField->CurrentValue;
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019
Server Events and Client Scripts Page 47 of 47
ExecuteRow($sql [,$dbname]) Executes the query, and returns the first row $row = ExecuteRow("SELECT * FROM
as an array. MyTable WHERE...");
ExecuteRows($sql [,$dbname]) Executes the query, and returns the rows as an $rows = ExecuteRows("SELECT * FROM
array. MyTable WHERE...");
ExecuteScalar($sql [,$dbname]) Executes the query, and returns the first $value = ExecuteScalar("SELECT MyField
column of the first row. FROM MyTable WHERE...");
ExecuteHtml($sql [,$options] [,$dbname]) Executes the query, and returns the data as $html = ExecuteHtml("SELECT * FROM
HTML table. See source code for options. MyTable WHERE...");
ExecuteJson($sql [,$options] [,$dbname]) Executes the query, and returns the data as $json = ExecuteJson("SELECT * FROM
JSON. See source code for options. MyTable WHERE...");
There are many other useful functions in the generated code, please refer to the source code of the file "phpfn*.php" in template or
generated scripts.
mk:@MSITStore:C:\Program%20Files%20(x86)\PHPMaker%202019\PHPMaker.ch... 07/08/2019