Page 1 of 1

Custom Error Message Before Insert

Posted: 2022-01-25 23:34
by angus
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;
	    }
	}

Re: Custom Error Message Before Insert

Posted: 2022-01-26 00:08
by jsetzer
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.

Re: Custom Error Message Before Insert

Posted: 2022-01-26 00:13
by jsetzer
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( ...

Re: Custom Error Message Before Insert

Posted: 2022-01-26 09:42
by angus
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.