How to define index on preCreate event?
How to define index on preCreate event?
I'm trying to make some calculations once the user submits the form to the database. I'm using the preCreate event but I'm getting this error:
<b>Notice</b>: Undefined index: notes_total in <b>C:\xampp\htdocs...
<b>Notice</b>: Undefined index: non_compl in <b>C:\xampp\htdocs...
Line 37 and 40
This is the PHP code:
<?php
/*
* Example PHP implementation used for the index.html example
*/
// DataTables PHP library
include( "../php/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\Upload,
DataTables\Editor\Validate;
// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'documentation' )
->fields(
Field::inst( 'documentation.full_name' )
->options('emp', 'name', 'name')
->validator( 'Validate::dbValues' ),
Field::inst( 'documentation.notes_total' ),
Field::inst( 'documentation.date' ),
Field::inst( 'documentation.compl' ),
Field::inst( 'documentation.office' ),
Field::inst( 'documentation.non_compl' ),
Field::inst( 'documentation.percent' )
)
->on( 'preCreate', function ($editor, $values ) {
$editor
->field( 'documentation.compl' )
->setValue($values['notes_total'] - $values['non_compl']);
$editor
->field( 'documentation.percent' )
->setValue((($values['notes_total'] - $values['non_compl']) / $values['notes_total']) * 100);
} )
->leftJoin( 'emp', 'emp.id', '=', 'documentation.full_name' )
->process( $_POST )
->json();
I tried using:
$values['documentation.notes_total']
But still same error
Any ideas on fixing this error? Thanks!
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Option 3 - use:
Allan
Thank you so much! Works like a charm!