One of the most flexible features that provided by PHPMaker is the ability to search records by using Advanced Search. This feature allows us to define which fields should be involved, and which operator should be used by default when users are accessing the Advanced Search page. For example, if you defined USER SELECT in Search Opr 1 column in Fields setup of PHPMaker, then in the generated Advanced Search pages will display the equal sign (=) as the default search operator. Users then are able to change that search operator in order to suits with their needs. For example, they will switch it become the not equal sign (<>), and so forth.
Sometimes, you want to define that default search operator for the string type fields become the contains (LIKE) and you are still using USER SELECT in Search Opr1 from PHPMaker. The question is, how can we do that, since there is no preference in PHPMaker to define which operator should be the default?
The answer is: We can even define it without having to modify the generated script files! As I mentioned above, PHPMaker has the flexible feature for this, even PHPMaker has not provided the related setting for this in Fields setup section. We are able to define the default search operator even we are using USER SELECT as the value in Search Opr1 of Advanced Search in PHPMaker. This following trick will show you how to define default search operator in Advanced Search pages of websites that generated by PHPMaker. We will define it from Server Events side of PHPMaker, so we can implement it for another projects. In the following example below, we will define the default search operator become contains (LIKE).
Updated on November 29, 2012: This customization has been implemented in PHPMaker version 9.1.0, it matches to each other, and as a result, it works properly.
Updated on February 10, 2013: This customization has been implemented in PHPMaker version 9.2.0, it matches to each other, and as a result, it works properly.
- Open your PHPMaker project (.pmp) file by using PHPMaker application.
- Expand your tables/views from Database pane in the left side of your PHPMaker application.
- Click on one of your desired tables/views, and you should see three tabs in the right pane of PHPMaker application. They are: Fields, Tables, and Code (Server Events, Client Scripts and Custom Templates). Now, make sure the Fields tab has been selected.
- Click on one of your desired fields from the right pane of PHPMaker application, then scroll to the most of right, you should see Advanced Search Page preference. Make sure in the Search column has been checked, and then in the Search Opr 1 has been chosen with USER SELECT value. Repeat this step for your another fields (if any).
The next step, we will write our own code from the Server Events to define the default search operator. To do this, make sure the selected table in the previous steps has been selected. Click on Code (Server Events, Client Scripts, and Custom Templates) and then expand this location: Server Events -> Table Specific -> Search Page -> Page_DataRendering, and then insert the following code into the Page_DataRendering function in editor code at the right pane of PHPMaker application:
$this->MyFirstStringField->AdvancedSearch->SearchOperator = "LIKE"; $this->MySecondStringField->AdvancedSearch->SearchOperator = "LIKE";
Please note that from the code above, we will define the default search operator of Advanced Search for two fields. Their name are: MyFirstStringField and MySecondStringField. Don't forget to adjust them with yours. It's very easy and simple, yet so powerful, isn't?
- Finally, re-generate your script files using PHPMaker as always.