Page 1 of 1

PHP BeforeSave return value

Posted: Sat Apr 22, 2023 8:17 pm
by mih
Hello!

According to https://wiki.nubuilder.cloud/index.php?title=Functions PHP BeforeSave event can stop saving process by value "No" (as on scheme). What and how PHP code should return for "YES" and "NO' values. I can't find any example in docs.

Re: PHP BeforeSave return value

Posted: Sat Apr 22, 2023 8:26 pm
by kev1n
Hi,

The diagram you are referring to only illustrates the possible paths that the "BeforeSave" event can take (continue saving or abort saving).
You can use the nuDisplayError() function to display an error message to the user to abort saving and display a message.

Example:

Code: Select all

// Some validation code to check if the data is valid
if (/* data is not valid */) {
    // Display an error message and stop the save process
    nuDisplayError('The data you entered is not valid.');
} else {
    // Allow the save to continue...
}

Re: PHP BeforeSave return value

Posted: Sun Apr 23, 2023 12:19 am
by mih
And is there aniother way to silently stop saving ?

Re: PHP BeforeSave return value

Posted: Sun Apr 23, 2023 1:24 pm
by kev1n
One approach that comes to mind is to promptly remove the message by declaring nuOnMessage() in the form's Custom Code:

Code: Select all

function nuOnMessage(msgDiv, errors) {
   if (errors == 'do_not_show_the_error') {
       msgDiv.remove();
       nuAbortSave();
   }
}
And in BS

Code: Select all

nuDisplayError('do_not_show_the_error');

Re: PHP BeforeSave return value

Posted: Sun Apr 23, 2023 5:02 pm
by mih
OK! Thanks!