Modal dialog function rowSelected edit page (v2024)

When the field is set to use Modal Dialog in the Preview Extension or in Master/Detail, the server throws an error. However, when I disable the modal dialog, everything works correctly. Below is the server-side code in the Row_Selected event:

public function rowSelected(&$rs)
{
    if (CurrentPageID() == 'edit' && !IsAdmin()) {
        $protocollo = intval($rs["id_rapporto"]);
        $id_azione_corrente = intval($rs["id_azione"]);
        $sql = "SELECT id_azione FROM rapporti_azione WHERE id_rapporto = " . intval($protocollo) . " ORDER BY id_azione DESC LIMIT 1";
        $value = ExecuteRow($sql);

        var_dump($value["id_azione"]);
        var_dump($protocollo);

        if ($value && $value["id_azione"] > $id_azione_corrente) {
            $this->setFailureMessage('You cannot modify this record.');
            $this->terminate('rapportilist'); // Redirect to the list page
        }
    }
}

Observations:

In Preview Page Edit, when the modal dialog is enabled, the server-side script fails and does not process correctly.
In Master/Detail, the same behavior is observed when using the modal dialog.
If I disable the modal dialog, the code works as expected in both cases.
Questions:

Is this a known issue with modal dialogs in PHPMaker for Preview or Master/Detail pages?
How can I ensure the modal dialog works correctly without causing server-side issues in these scenarios?
Environment:

PHPMaker Version: 2024
Thank you for your assistance.

error: Uncaught Error: Syntax error, unrecognized expression: string(24) “Ultimo ID Azione: 199996”
string(23) “Protocollo Corrente: 13”

This look like JavaScript errors not related to your server side code. You should enable Debug and check the server side error logs for errors raised by your code. You may use Log() instead of var_dump() so what you want to check will be logged in the log file, e.g.

// Note: The second argument is array
Log("rs", $rs);
Log("sql", [$sql]);
Log("value", $value]);

:frowning: changing from var_dump to Log … magically everything worked. By reporting the error in var_dump it recurred. So with the var_dump and the modal_dialog enabled it generated the error. Solved.

That was because your output from var_dump() broke the original JSON output.