Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

If only the key names of the $data array are of interest, that is always the database row that is being validated. The The columns that belong to the table can be found in the Data Dictionary: by navigating to "Admin > Data Dictionary"

Look up the table that the code is being written for, the column names are the keys that are expected to be seen in that variable, this will enable references to them to be made in the code. For example, SERVICES:

...

  1. Custom Validation - see the code being written
    • Navigate to "Admin > Custom Logic > Validation" to view the records.
  2. Form the Validation runs against (example from above, Service Form)
  3. In the Custom Validation code, add this to the top:

    Code Block
    languagephp
    linenumberstrue
    $dataMap = [];
    // Covers undefined variable bug - $data IS defined during execution
    if (!isset($data)) {
    $data = [];
    }
    foreach ($data as $column => $item) {
    // Replace strings for values that don't convert well
    // switch isn't naturally type-strict, so the cases need to be.
    switch (true) {
    case $item === null:
    $item = 'null';
    break;
    case $item === true:
    $item = 'true';
    break;
    case $item === false:
    $item = 'false';
    break;
    case $item === '':
    $item = '{empty string}';
    break;
    }
    $dataMap[] = $column . ' => ' . $item;
    }
    $this->setError(implode("<br>", $dataMap));
    return false;


  4. Once that's added to the CV code, go to the Form where the CV is applied. Save the record.

...