In my previous two articles, I wrote tips and tricks how you can prevent blank search keyword in Search panel for Basic Search in List pages, and also how to define default search operator in Advanced Search pages. Now we are going to add the ability in Advanced Search page to force users to select values before doing the search process. Let's say, users will be able to search for the customers details before they selected the Province, Regency, and Subdistrict that belong to the customers. If users have not selected those three values, then system will display the warning message and will not allow users to procede to the search process.
This is very useful if you want to add the certain pre requirement in Advanced Search in order to narrow the search results. So your web application will only return the search results that match to the selected values that chosen by users. In the following example, we will use the Province, Regency, and Subdistrict fields as the mandatory fields for Advanced Search. It means that those three fields need to be selected by end-users before procede to the search process itself. As we have already known, PHPMaker has not provided this related settings, even those three fields have been setup as Required from the Fields setup, they will not be treated as the mandatory in Advanced Search page.
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.
[hidepost]
- Open your PHPMaker project (.pmp) file using PHPMaker application.
- Expand your tables/views from Database pane in the left side of your PHPMaker application, then click on one of your desired tables, and make sure you have already seen now the three tabs appear in the right side of your PHPMaker application: Fields, Table, and Code (Server Events, Client Scripts and Custom Templates).
- Now click on Code (Server Events, Client Scripts and Custom Templates) tab.
-
Expand or go to the following location: Server Events -> Table-Specific -> Search Page -> Form_CustomValidate, aftewards, copy and paste the following code into the Form_CustomValidate function:
global $Language; // Return error message in CustomError // Note: Don't forget to adjust Province, Regency, and Subdistrict with your fields name! if ($this->Province->AdvancedSearch->SearchValue == "") { $CustomError = $Language->Phrase("ProvinceIsNotSelected"); return FALSE; } elseif ($this->Regency->AdvancedSearch->SearchValue == "") { $CustomError = $Language->Phrase("RegencyIsNotSelected"); return FALSE; } elseif ($this->Subdistrict->AdvancedSearch->SearchValue == "") { $CustomError = $Language->Phrase("SubdistrictIsNotSelected"); return FALSE; } else { return TRUE; } -
The next step, we will add three new phrases in the .xml language file. To do this, open your C:\Program Files\PHPMaker 9\languages\english.xml file, and then find this code:
</global>
before the line of that code, please insert the following code:
<phrase id="ProvinceIsNotSelected" value="Province has not been selected, yet."/> <phrase id="RegencyIsNotSelected" value="Regency has not been selected, yet."/> <phrase id="SubdistrictIsNotSelected" value="Subdistrict has not been selected, yet."/> -
Do the same step as the previous step above for your another .xml language file. For example, I am also using Indonesian language for my web application, then I will add those phrases to my indonesian.xml file as following (adjust it with your another languages):
<phrase id="ProvinceIsNotSelected" value="Propinsi belum dipilih."/> <phrase id="RegencyIsNotSelected" value="Kabupaten/Kota belum dipilih."/> <phrase id="SubdistrictIsNotSelected" value="Kecamatan belum dipilih."/> - Finally, re-generate your script files using PHPMaker as always, and enjoy the results.
[/hidepost]
Leave a Reply
You must be logged in to post a comment.