$values and $row are empty in postCreate callback

$values and $row are empty in postCreate callback

TomBajzekTomBajzek Posts: 163Questions: 36Answers: 1

I have a postCreate event handler in my server-side PHP code that gets errors for undefined indexes in the $values and $row return arrays. This, of course, gives the diagnostic A system error has occurred because the JSON returned is invalid. I don't know how to fix this. The record itself is created correctly, and the data portion of the JSON returned is correct. The problem is that the error diagnostics concerning the undefined indexes that precede the returned record are not valid JSON.

I have similar code that works in other applications, but I cannot see what is causing the error in this case, as**** it does not fail in the similar cases.

The excerpted editor code for the fields in question is as follows:

    {
        "label": "originator:",
        "name": "tickets.originator",
        "placeholder": "Choose",                    
                    def: function() {
                        var user = $('#theUser').attr('data-user');
                        return user;
                }
    },
    {
        "label": "category:",
        "name": "tickets.category",
            "type": "select",
            "multiple": true,
            "separator": ', ',
                    "placeholder": "Choose",
                    "options": [
                    ]
    },
    {
        "label": "description:",
        "name": "tickets.description",
        "type": "textarea",
         attr: {
            "class": "form-control desc"
        }
    }

The excerpted postCreate handler PHP code is:

    ->on('postCreate', function($editor,$id,$values,$row) { // Notify techs of new ticket
        notify($id,$values['tickets.category'],$values['tickets.description'],$values['tickets.originator']);
    } )

The function notify is defined elsewhere to send email to the originator, alerting him to the ticket those fields include the category and description. Similar code on other instances of this type of application work correctly. The indexes tickets.category, tickets.description, and tickets.originator are qualified names because there is a field from another table defined in the editor, but that one is not involved in the failure. Also, I've tried using the unqualified index names, but that makes no difference.

The JSON response is as follows:

<br />
<b>Notice</b>: Undefined index: category in <b>/var/www/vhosts/bajzek.com/asccintranet.bajzek.com/FleetTracker/php/table.tickets.php</b> on line <b>182</b><br />
<br />
<b>Notice</b>: Undefined index: description in <b>/var/www/vhosts/bajzek.com/asccintranet.bajzek.com/FleetTracker/php/table.tickets.php</b> on line <b>182</b><br />
<br />
<b>Notice</b>: Undefined index: tickets.category in <b>/var/www/vhosts/bajzek.com/asccintranet.bajzek.com/FleetTracker/php/table.tickets.php</b> on line <b>185</b><br />
<br />
<b>Notice</b>: Undefined index: tickets.description in <b>/var/www/vhosts/bajzek.com/asccintranet.bajzek.com/FleetTracker/php/table.tickets.php</b> on line <b>185</b><br />
<br />
<b>Notice</b>: Undefined index: tickets.category in <b>/var/www/vhosts/bajzek.com/asccintranet.bajzek.com/FleetTracker/php/table.tickets.php</b> on line <b>185</b><br />
<br />
<b>Notice</b>: Undefined index: tickets.description in <b>/var/www/vhosts/bajzek.com/asccintranet.bajzek.com/FleetTracker/php/table.tickets.php</b> on line <b>185</b><br />
<br />
<b>Notice</b>: Undefined index: tickets.category in <b>/var/www/vhosts/bajzek.com/asccintranet.bajzek.com/FleetTracker/php/table.tickets.php</b> on line <b>186</b><br />
<br />
<b>Notice</b>: Undefined index: tickets.description in <b>/var/www/vhosts/bajzek.com/asccintranet.bajzek.com/FleetTracker/php/table.tickets.php</b> on line <b>186</b><br />
<br />
<b>Notice</b>: Undefined index: tickets.originator in <b>/var/www/vhosts/bajzek.com/asccintranet.bajzek.com/FleetTracker/php/table.tickets.php</b> on line <b>186</b><br />
{"data":[{"DT_RowId":"row_307","tickets":{"id":"307","created":"2018-10-29 19:27:56","updated":"2018-10-29 19:27:56","vehicle_id":"113","status":"in queue","originator":"tom","category":"Gauges Broken","description":"test"},"vehicles":{"bareTag":"54","color":"","modelYear":"2010","maker":"Honda","model":"Insight","type":"car"},"assignments":{"person":"hoffmanjm"}}]}

Note that the data returned in the JSON response appears (to me) to be well-formed, and it corresponds the the record that was actually created.

Can you see what is wrong here?

Thanks for looking at this,
Tom

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin
    Answer ✓

    Don't use $values['tickets.category']. Its a nested array, not a flat one. $values['tickets']['category'] is the correct style to use.

    Note that the data returned in the JSON response appears (to me) to be well-formed,

    Without the errors, yes it is well formed JSON. But the errors are there, and that is making the response as a whole invalid JSON.

    Allan

  • TomBajzekTomBajzek Posts: 163Questions: 36Answers: 1

    That did it!

    Thanks for correcting my error,
    Tom

This discussion has been closed.