How to define index on preCreate event?

How to define index on preCreate event?

bjshortybjshorty Posts: 20Questions: 6Answers: 0

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

Answers

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Answer ✓

    Option 3 :smile: - use:

    $values['documentation']['notes_total']
    

    Allan

  • bjshortybjshorty Posts: 20Questions: 6Answers: 0

    Thank you so much! Works like a charm!

This discussion has been closed.