Javascript Alerts not showing up in Appgini version 5.00

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
vassikou
Posts: 5
Joined: 2013-06-30 21:58

Javascript Alerts not showing up in Appgini version 5.00

Post by vassikou » 2013-06-30 22:25

Hello Appgini Forum Users,

I have made the following customizations to the TableName_Before_Insert function of a table named Appointments at the Appointments.php file under the Hooks folder (code generated with the latest version of Appgini):

Code: Select all

	function Appointments_before_insert(&$data, $memberInfo, &$args){
		// Check if the Name and Surname exist in the WatchList. If yes insert an ALERT message to the Comments field
		// and show a warning alert message to the user
		$name=$data['Name'];
		$surname=$data['Surname'];
		$res=sql(
			"SELECT firstname, lastname " .
			"FROM WatchList WHERE " .
			"UPPER(FirstName) = UPPER('$name') and " .
			"UPPER(LastName) = UPPER('$surname')"
		, $eo);
		
		//Check if query brings up any results then show alert message and put a color coded message in the Comments field of the appointment and bring up the ALERT
		if(mysql_num_rows($res)){
			$data['Comments'] = '<b><font color="#E56717">***ALERT. Check Watch List for details!***.</font></b>' . $data['Comments'];
			do_alert("CAUTION:A person with the same Name and Surname was found in Watch List...");
		}
		return TRUE;
	}
where do_alert function is defined as:

Code: Select all

function do_alert($msg) 
    {
        echo '<script type="text/javascript">alert("' . $msg . '"); </script>';
    }
The code was working perfectly fine up until Appgini 4.70 but after that version, if there is a match to the Watchlist tablethe the alert message is not displayed at all to the user, althought the row is inserted into the Appointments table with the COMMENTS field properly changed, which means that the if(mysql_num_rows($res)) {...} code is being normally executed.

Following another discussion http://forums.appgini.com/phpbb/viewtopic.php?f=7&t=565 I tried to use the Modalbox.show insted of the above Javascript do_alert function but I get an error that the function is undefined.

So, I wanted to ask what has caused the Javascript Alert function to stop functioning in this case and what should I do to display a warning message to the user when there is a match in if(mysql_num_rows($res)) {...} code ?

Thank you very much in advance
Vassilis

User avatar
a.gneady
Site Admin
Posts: 1281
Joined: 2012-09-27 14:46
Contact:

Re: Javascript Alerts not showing up in Appgini version 5.00

Post by a.gneady » 2013-07-01 20:48

Try altering do_alert() to:

Code: Select all

function do_alert($msg)
{
        echo '<script>Modalbox.show("<div>' . addslashes($msg) . '</div>"); </script>';
}
:idea: AppGini plugins to add more power to your apps:
  • DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
  • Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
  • Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.

vassikou
Posts: 5
Joined: 2013-06-30 21:58

Re: Javascript Alerts not showing up in Appgini version 5.00

Post by vassikou » 2013-07-02 12:05

Dear Ahmad, thank you for your reply.

Tried that and didn't make any difference. No ALERT message appears. My impression is that Modalbox library, for some strange reason, is out of range for the .php files residing in the hooks folder. How can I explicitly include it in my php file?

vassikou
Posts: 5
Joined: 2013-06-30 21:58

Re: Javascript Alerts not showing up in Appgini version 5.00

Post by vassikou » 2013-07-05 07:46

Has anyone else tried something similar?

User avatar
a.gneady
Site Admin
Posts: 1281
Joined: 2012-09-27 14:46
Contact:

Re: Javascript Alerts not showing up in Appgini version 5.00

Post by a.gneady » 2013-07-10 16:15

I'm so sorry for the long delay. I guess the reason it's not working is that you're returning true from the hook after calling the modalbox ... returning true tells the application that it's OK to insert the record to the database and then the user is redirected to a new page and never sees the alert from the hook ... You should instead return false so that the record is not inserted and the user sees the alert.
:idea: AppGini plugins to add more power to your apps:
  • DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
  • Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
  • Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.

Post Reply