Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

PHP BeforeSave return value Topic is solved

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
mih
Posts: 30
Joined: Thu Jan 26, 2023 12:04 pm
Has thanked: 3 times

PHP BeforeSave return value

Unread post 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.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: PHP BeforeSave return value

Unread post 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...
}
mih
Posts: 30
Joined: Thu Jan 26, 2023 12:04 pm
Has thanked: 3 times

Re: PHP BeforeSave return value

Unread post by mih »

And is there aniother way to silently stop saving ?
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: PHP BeforeSave return value

Unread post 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');
mih
Posts: 30
Joined: Thu Jan 26, 2023 12:04 pm
Has thanked: 3 times

Re: PHP BeforeSave return value

Unread post by mih »

OK! Thanks!
Post Reply