Custom Error Message Before Insert

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
angus
Veteran Member
Posts: 128
Joined: 2020-05-28 22:27

Custom Error Message Before Insert

Post by angus » 2022-01-25 23:34

Hello board I need some help if you can. I need to get a custom error message built into my before update hook but nothing I am doing is working. I just get the standard 'Couldn't save the new record'. I am using v5.82

Code: Select all

function checklist_before_insert(&$data, $memberInfo, &$args) {
		
				// WORK OUT MONTH YEAR
				$UKDate=$_REQUEST['DateLeavingMonth'].$_REQUEST['DateLeavingYear'];
		
				// set up unique check 
				$Uk=$data['EMPLOYEEID'].$UKDate;				
				
				// list the unique keys in an array
				$res = sql("SELECT Unique_Check_Value FROM checklist",$eo);
					WHILE($row = db_fetch_row($res)){
						$uks[]=$row[0];
					}
				// if unique key already exists do not save the record
				IF(in_array($Uk, $uks)){
					
				       return FALSE;
				}else{
				
	
		return TRUE;
	    }
	}
AppGini 22.13

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1944
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Custom Error Message Before Insert

Post by jsetzer » 2022-01-26 00:08

Don't know if this helps: There is a new feature for custom messages, see here:

https://bigprof.com/appgini/help/advanc ... ore_insert

On that page please check the chapters for "before insert" and "before update" hooks:
As of AppGini 5.90, if returning false, an error message string (no HTML tags allowed) can be displayed to users by passing it through $args['error_message'].
$args['error_message'] can be set inside the hook function to display an error message to user in case of returning false.
I did not use it, yet, but this could be what you have been searching for.

You could consider updating to the latest AppGini version. These options are availability since version 5.90.
Last edited by jsetzer on 2022-01-26 00:17, edited 2 times in total.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 25.10 + all AppGini Helper tools

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1944
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Custom Error Message Before Insert

Post by jsetzer » 2022-01-26 00:13

By the way: maybe you do your code changes at the wrong place/wrong function:

In your question you write...
before update
...but the code is for ...

Code: Select all

function checklist_before_insert( ...
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 25.10 + all AppGini Helper tools

angus
Veteran Member
Posts: 128
Joined: 2020-05-28 22:27

Re: Custom Error Message Before Insert

Post by angus » 2022-01-26 09:42

thanks Jan, yes check is before insert, sorry for causing confusion.

I will need to test this on a development server, upgrade to 5.9*, as I don't want anything to break.
AppGini 22.13

Post Reply