index or variable not found in preCreate

index or variable not found in preCreate

FicosFicos Posts: 88Questions: 22Answers: 0

I keep this error coming:

Undefined variable: filter in D:\website\studio\test_debiteuren\php\table.datatables_demo.php on line 34
{"data":[]}

If I change $filter to $_POST['dossier'] error is

Undefined index: dossier in

I have been reading several items here, but I don't see any solution.

this is php-code:

<?php

/*
 * Editor server script for DB table datatables_demo
 * 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
$filter = isset($_POST['dossier'])?$_POST['dossier']:1747;  //filter recordset according to currently selected row
Editor::inst( $db, 'datatables_demo', 'id' )
    ->fields(
        Field::inst('clientID')->set( Field::SET_CREATE ),
        Field::inst( 'first_name' ),
        Field::inst( 'last_name' ),
        Field::inst( 'position' )
    )
    ->on( 'preCreate', function ( $editor, $values ) {
        $editor
            ->field( 'clientID' )
            ->setValue($_POST['dossier']);
    })
    ->where('clientID',$filter)
    ->process( $_POST )
    ->json();

Example available on http://oostveen-advies.eu/test/datatables_demo.html

Thank you

Answers

This discussion has been closed.