This topic is locked

BeforeEdit with Input Validation in combination with multiple updates

2/2/2026 13:06:28
PHPRunner General questions
A
Andreas author

Hi :)

I am doing some input validation on Add and Edit pages.
Somethink like:

  • check if $values['val1'] is valid in combination with $values['val2']

Pseudo code:

function BeforeEdit(...)
if ($values['val1'] is invalid in combination with $values['val2'])
{
$message = 'val1 is useless in combination with val2';
return false;
}
// return true if everything is okay
return true;

It works perfectly as long I am only updating one row.

When updating multiple (5 for example) rows with negative result each then it shows me

val1 is useless in combination with val2
val1 is useless in combination with val2
val1 is useless in combination with val2
val1 is useless in combination with val2
val1 is useless in combination with val2

(Error message 5 times).
Still perfect :)

But if even one of the rows is correct, then the "return true" closes the dialog and there won't be a single error message.
The user is not getting informed about the non validated updates.

Fortunately the 4 "wrong" rows aren't updated. But it's not nice to get no error message.

Is there any way to only close the dialog when every validation is correct and not a single "return false" occurred?
Something like iterating every single update steps and setting a variable to false if something went wrong.
And in the end only when the variable isn't false then the last "return true" will be executed.

(I am using PHPRunner 11.2 Enterprise build 44123)

ChatGPT 2/2/2026

In PHPRunner, when you're dealing with multiple updates and want to ensure that all validation checks are passed before closing the dialog, you can implement a mechanism to aggregate the validation results. Instead of returning immediately on the first failure, you can collect error messages and return them all at once if there are any issues.

Here's a modified approach to your BeforeEdit function:

function BeforeEdit(&$values, &$where, &$oldvalues, &$keys) {
// Initialize an array to store error messages
$errorMessages = [];

// Example validation for each row
foreach ($values as $key => $row) {
if (invalidCombination($row['val1'], $row['val2'])) {
$errorMessages[] = "Row $key: val1 is useless in combination with val2";
}
}

// Check if there are any error messages
if (!empty($errorMessages)) {
// Join error messages into a single string
$message = implode('
', $errorMessages);
// Set the error message
$message = $message;
// Return false to prevent closing the dialog
return false;
}

// Return true if everything is okay
return true;
}

// Example function to check the validity of val1 and val2
function invalidCombination($val1, $val2) {
// Your validation logic here
return false; // Change this to your actual validation logic
}

Explanation:

  1. Collecting Errors: We initialize an array $errorMessages to store any validation errors.
  2. Iterating Through Rows: We loop through the $values array, checking each row for validity.
  3. Storing Messages: If a row fails validation, we add an appropriate error message to the $errorMessages array.
  4. Returning Messages: After the loop, we check if there are any error messages. If there are, we join them into a single string with line breaks and set the $message variable.
  5. Preventing Dialog Closure: Finally, we return false if there are any errors, keeping the dialog open for the user to see all error messages.

This way, if even one of the rows fails validation, the dialog will remain open and display all relevant error messages to the user, allowing them to make the necessary corrections before submitting again.

Sergey Kornilov admin 2/2/2026

It looks like you are not providing the whole picture. On Add and Edit pages there is only one record and it is not clear what "It works perfectly as long I am only updating one row." means in this context.

C
Chris Whitehead 2/3/2026

Would I be correct in thinking that you're using the list page, selecting the records using the checkbox and using a dialog or popup to update all the records?

A
Andreas author 2/3/2026

@Chris Whitehead yes, thats correct.
I am selecting multiple records on list on a list page and click the "update multiple" button.
Then a diaglog-box appears and I am able to select the options (columns) I want to change.
Saving this dialog calls the BeforeEdit event with $oldvalues and $values of every record selected. So I can validate the changes there.

Setting the $message variable to something and returning false shows an error message.
But only if
a.) I edit a single record - not multiple ones - which returns false
b.) I am updating multiple records and all of them do return false
If one of the selected records return true, then there will be no error message at all. Even for the records who didn't got updated.

Sorry if I couldn't tell it more clearly. If you want, then I can record my screen and upload it to youtube :)

C
Chris Whitehead 2/3/2026

@Andreas,

I think you need to add the code into the server section of the button and loop through the selected records as this code snippet

// this would go into the server section of the button, this is just pseudo code so update.
$result["message"] = '';
while($values = $button->getNextSelectedRecord())
{
// check the values at this point

if ($values['val1'] is invalid in combination with $values['val2'])
{
$result["message"] .= = 'val1 is useless in combination with val2
';
} else {
// then update the record here.
}
}
// then this into the client after to display the errors or sucesses
ajax.setMessage( result["message"] );