This topic is locked
[SOLVED]

Before Record Added - error on return false

6/16/2021 11:50:25 AM
PHPRunner General questions
S
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.

S
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:
unset($_SESSION["quote2title"]);

...which created the return false error.

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

$values["itemsID"] = $_SESSION["quote2title"];
//unset($_SESSION["quote2title"]);
if ($values["quote"] == "")
{
$message = "Please add a quote";
return false;
}
else
{
unset($_SESSION["quote2title"]);
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.