The following trick will show you how to display the welcome message to your users after they are successfully logged in to your web application that generated with PHPMaker 8.0.3. This message will be displayed on the first next page your users will see after they have successfully logged in to your site, no matter what page that they will see the first time after logged in.
The welcome message will include the complete name of your logged in user. For example, one of your users' username is: johndoe and the complete name of him is John Doe (first name is John, and the last name is Doe), so the welcome message that will be shown is: Welcome, John Doe!.
Please note that if you want to display the auto-hide message in three seconds, then please apply this customization.
All we have to do is customizing the PHPMaker template file and adding some code into the Server Events section of PHPMaker. In other words, we do not modify any generated script files.
Please click on the following image below to watch the demo:
[hidepost]
-
Open your .pmp PHPMaker project file using your PHPMaker application, click on the Database icon on the toolbar, and then click on the Server Events/Clients Scripts tab, go to the Server Events -> Other -> Login Page -> User_LoggedIn, and then add the following code into that function:
global $Security, $Language; $this->setSuccessMessage($Language->Phrase("Welcome").", ". $Security->CurrentCompleteName()."!");
- Make sure you have added the "Welcome" phrase into the C:\Program Files\PHPMaker 8\languages\english.xml file and also the other .xml language file (if any). To add a new phrase into the .xml language file, please read this article.
-
Open your /Script/phpfn.php file, and find this code:
function setCurrentUserName($v) { $_SESSION[EW_SESSION_USER_NAME] = $v; }
after the last line of that code, please insert this following code:
function CurrentCompleteName() { global $conn; $first_name = "nama_awal"; // <-- adjust it with your real first name field $last_name = "nama_akhir"; // <-- adjust it with your real last name field $currentUserName = $this->getCurrentUserName(); if (($rs = $conn->Execute("SELECT ".$first_name.", ".$last_name." FROM ".EW_USER_TABLE." WHERE ".EW_USER_ID_FIELD." = '".$currentUserName."'")) && !$rs->EOF) { $completeUserName = $rs->fields($first_name) . " " . $rs->fields($last_name); $rs->Close(); } return $completeUserName; }
Please do not forget to adjust the values of the $first_name and $last_name variables above.
-
Open your /Script/ewcfg.php file, and find this code:
define("EW_USER_NAME_FILTER", "<!--##=ew_Quote(sFilter)##-->", TRUE);
before the first line of that code, please insert the following code:
<!--## If PROJ.SecLoginIDFld <> "" Then Set FIELD = SECTABLE.Fields(PROJ.SecLoginIDFld) sFld = ew_FieldName End If ##--> define("EW_USER_ID_FIELD", "<!--##=sFld##-->", TRUE);
[/hidepost]
“EW_USER_ID_FILTER” returns null !!! I hard coded it to get the function working.
What do you mean “I hard coded it to get the function working”? I don’t think that “EW_USER_ID_FILTER” constant is used in this article.
Sorry for the typo, I mean the constant “EW_USER_ID_FIELD” returns error (there is no such constant in php template, unless you’ve added it) , so I had to hardcode username field in the select statement.
Ah, I see. You are right. Apologize for the uncovenience, and thanks for bringing this issue up.
Please follow the step number 4 in order to add the related constant into the configuration file.
It seems to me that you can accomplish the same using “server events – Global Code” without the need to edit the template … is there a reason behind it? .. maybe performance ?? Thanks.
Well, the reason for this since I wanted to use the Security class that provided in the template file, so that I customized the class in the template file by adding the new function. In addition, this template can be re-used by another project without having to add the code from the Global Code section of PHPMaker application.
Makes sense, Thanks 🙂
For 9.10, the following code:
…needs to be changed to:
Thanks for the feedback.