Fatal Error: Uncaught Error on line 635 of Editor\Validate.php

Fatal Error: Uncaught Error on line 635 of Editor\Validate.php

DatagaardDatagaard Posts: 68Questions: 20Answers: 3

I have created a DataTables Editor using the generator and attempted to create a record via the editor and have received an error "A system error has occurred".

Here is the Firefox error data:

The frequency.php code:

<?php

/*
 * Editor server script for DB table frequency
 * Created by http://editor.datatables.net/generator
 */

// DataTables PHP library and database connection
include( "lib/DataTables.php" );

// Alias Editor classes so they are easy to use
use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Mjoin,
    DataTables\Editor\Options,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate,
    DataTables\Editor\ValidateOptions;

// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'frequency', 'frequency.frequencyid' )
    ->fields(
        Field::inst( 'frequency.organisationid' )
            ->options( 'organisation','organisationid', 'orgname')
            ->validator( 'Validate::dbValues' ),
        Field::inst( 'organisation.orgname' ),
        Field::inst( 'organisation.inactive'),
        Field::inst( 'frequency.fdescription' )
            ->validator( Validate::notEmpty( ValidateOptions::inst()
                ->message('A Description is required') ) )
            ->validator( Validate::minMaxLen( 1, 50 ) ),
        Field::inst( 'frequency.offsetindays' )
            ->validator( Validate::notEmpty( ValidateOptions::inst()
                ->message('Offset in days is required') ) )
            ->validator( Validate::minNum( 1, ValidateOptions::inst()
                ->message( 'Offset In days greater than 0' ) ) ),
        Field::inst( 'frequency.isdeleted' )
            ->setFormatter(function ($val, $data, $opts) {
                return ! $val ? 0 : 1;          
            })
    )
    ->leftJoin( 'organisation', 'organisation.organisationid', '=', 'frequency.organisationid')
    ->process( $_POST )
    ->json();

<?php
>
```
?>


Here is the frequency.js

/*
* Editor client script for DB table frequency
* Created by http://editor.datatables.net/generator
*/

(function($){

$(document).ready(function() {
var editor = new $.fn.dataTable.Editor( {
ajax: 'php/table.frequency.php',
table: '#frequency',
fields: [
{
"label": "Organisation:",
"name": "frequency.organisationid",
"type": "select"
},
{
"label": "Description:",
"name": "frequency.fdescription"
},
{
"label": "Offset In days:",
"name": "frequency.offsetindays"
},
{
"label": "Is Deleted:",
"name": "frequency.isdeleted",
"type": "checkbox",
"separator": "|",
"options": [
{label: '', value: 1}
]
}
]
} );

var table = $('#frequency').DataTable( {
    ajax: 'php/table.frequency.php',
    columns: [
        { 
            "data": "organisation.orgname",
            "render": function (data, type, row){
                if (row.organisation.inactive == 0){
                    return data + '(Inactive)';
                }
                else{
                    return data;
                }
            }
        },
        {
            "data": "frequency.fdescription"
        },
        {
            "data": "frequency.offsetindays"
        },
        {
            "data": "frequency.isdeleted",
            "render": function (data, type, row){
                if (type === 'display'){
                    return '<input type="checkbox" class="editor-active">';                 
                }
                return data;                
            },
            "className": "dt-body-center"
        }
    ],
    select: true,
    lengthChange: false,
    responsive: true,
    rowCallback: function (row, data) {
     // Set the checked state of the checkbox in the table
     $('input.editor-active', row).prop('checked', data.isdeleted ==1);
  }
} );

new $.fn.dataTable.Buttons( table, [
    { extend: "create", editor: editor },
    { extend: "edit",   editor: editor },
    { extend: "remove", editor: editor }
] );

table.buttons().container()
    .appendTo( $('.col-md-6:eq(0)', table.table().container() ) );

} );

$('#frequency').on( 'change', 'input.editor-active', function () {
    editor
        .edit( $(this).closest('tr'), false )
        .set( 'frequency.isdeleted', $(this).prop( 'checked' ) ? 1 : 0 )
        .submit();
} );

$('#frequency').on( 'init.dt', function(e, settings, json) {
var select = editor.field( 'frequency.organisationid').input();
var jData = json.data;
var OrgIsAvail = 0;
var disabledOrgs = [];
var OrgObj = {};
for(i = 0; i < jData.length; i++){
OrgID = jData[i]['frequency'].organisationid;
OrgIsAvail = jData[i]['organisation'].inactive;
if (OrgIsAvail == 1){
// put the number in the object (as a key)
OrgObj[OrgID] = true;
}
}

    // copy numbers out of object into array
    for (var l in OrgObj){
        if (OrgObj.hasOwnProperty(l)){
            disabledOrgs.push(l);       
        }       
    }       
var orgOpt = '';
for(j = 0; j < select[0].length; j++){
    orgOpt = select[0][j];
    for (k = 0; k < disabledOrgs.length; k++){
            if (orgOpt.value == disabledOrgs[k]){
                orgOpt.setAttribute('disabled','disabled');
                break;
            }           
    }
}

});
}(jQuery));


And here is the frequency.html:

<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />

    <title>DataTables Editor - frequency</title>

    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4-4.1.1/jq-3.3.1/moment-2.18.1/dt-1.10.18/b-1.5.6/b-flash-1.5.6/b-print-1.5.6/fh-3.1.4/r-2.2.2/sl-1.3.0/datatables.min.css">
    <link rel="stylesheet" type="text/css" href="css/generator-base.css">
    <link rel="stylesheet" type="text/css" href="css/editor.bootstrap4.min.css">

    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="https://cdn.datatables.net/v/bs4-4.1.1/jq-3.3.1/moment-2.18.1/dt-1.10.18/b-1.5.6/b-flash-1.5.6/b-print-1.5.6/fh-3.1.4/r-2.2.2/sl-1.3.0/datatables.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/dataTables.editor.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/editor.bootstrap4.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/table.frequency.js"></script>
</head>
<body class="bootstrap4">
    <div class="container">

        <h1>
            DataTables Editor <span>frequency</span>
        </h1>

        <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="frequency" width="100%">
            <thead>
                <tr>
                    <th>Organisation</th>
                    <th>Description</th>
                    <th>Offset In Days</th>
                    <th>Is Deleted</th>
                </tr>
            </thead>
        </table>

    </div>
</body>

</html>

```
Here is the MySQL table code:

Hoping that someone could point out my error.

Thanks in advance

This question has an accepted answers - jump to answer

Answers

  • DatagaardDatagaard Posts: 68Questions: 20Answers: 3

    After some more investigation, and commenting out the Validators the error has changed to data too long for isdeleted?

  • DatagaardDatagaard Posts: 68Questions: 20Answers: 3
    edited July 2019

    It appears that the Validate.php has an issue with an MySQL datacolumn set to a "BIT" type.

    The Validators are also causing problems. If I comment them out too, the code now works

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    The error indicates an issue is with this line of code. It also suggests for some reason that PHP is attempting to namespace the function, even although its a PHP built in function.

    What version of PHP are you using please? I think this is an issue that will be addressed by upgrading your PHP install.

    Allan

  • DatagaardDatagaard Posts: 68Questions: 20Answers: 3

    Hi Allan,

    The version of php is 7.2.10

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Oh wow. I'd been thinking it might be 5.3.x.

    I wonder if your PHP has been installed without multi-byte strings? Does the phpinfo output say anything about mb? What is the configure line?

    Allan

  • DatagaardDatagaard Posts: 68Questions: 20Answers: 3

    Hi Allan,

    Could't see anything relating to mb eihter in phpInfo or the php.ini file.

    phpInfo is too large to attach

    Configuration Command

    Configure Command   cscript /nologo configure.js "--enable-snapshot-build" "--enable-debug-pack" "--with-pdo-oci=c:\php-snap-build\deps_aux\oracle\x64\instantclient_12_1\sdk,shared" "--with-oci8-12c=c:\php-snap-build\deps_aux\oracle\x64\instantclient_12_1\sdk,shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet=shared" "--without-analyzer" "--with-pgo" 
    
    
  • DatagaardDatagaard Posts: 68Questions: 20Answers: 3
    edited August 2019

    Hi Allan,

    Is this what you are looking for, from php.ini file:

    Also

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Answer ✓

    Thanks! I hadn't realised that mb_* could be disabled in PHP. I've committed a fix that will allow for this.

    Regards,
    Allan

This discussion has been closed.