This topic is locked

Before Record Added - error on return false

PHPRunner General questions
smez author

I get an error message when trying to use return false in a Before Record Added event:

Fatal error: Uncaught Error: Call to a member function value() on bool in.../include/events.php on line...

return true adds the record OK.

Any suggestions for how I fix this?

admin 6/16/2021

Show us your exact code in this event.

smez author 6/16/2021

I have figured this out.

I am using a session variable created by a custom button before redirecting to the add page:

$values["itemsID"] = $_SESSION["quote2title"];

..and then immediately unset the session variable:

...which created the return false error.

The solution is to only unset the session variable if return is true:

$values["itemsID"] = $_SESSION["quote2title"];
if ($values["quote"] == "")
$message = "Please add a quote";
return false;
return true;

The code above is a simplified version of my Before Record Added code but it illustrates the problem and solution for my server side validation when I need to use session variables in $values.