Global Validator - Undefined Index
Global Validator - Undefined Index
peterbrowne
Posts: 314Questions: 54Answers: 0
in Editor
I'm trying to use the global validator as per the example at:
https://editor.datatables.net/manual/php/validation#Examples
I'm getting an error:
Notice: Undefined index: learning_event.low_vision in /var/www/html/curriculum_mapper/programs/cm_dopt/program_data/learning_event_test_only_data.php on line 114
{"error":"Low vision is not 2","data":[]}
The code is:
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate,
DataTables\Editor\ValidateOptions;
Editor::inst( $db_cm_dopt, 'learning_event', 'learning_event_pk' )
->field(
Field::inst( 'learning_event.learning_event_name' ),
Field::inst( 'learning_event.outline' ),
Field::inst( 'learning_event.low_vision' ),
Field::inst( 'learning_event.contact_lenses' ),
Field::inst( 'learning_event.paediatrics' ),
Field::inst( 'learning_event.binocular_vision' ),
Field::inst( 'learning_event.vision_therapy' ),
Field::inst( 'learning_event.therapeutics' ),
Field::inst( 'learning_event.research' ),
Field::inst( 'learning_event.clinical_practice' ),
Field::inst( 'learning_event.optics' ),
Field::inst( 'learning_event.broad_vision_sciences' ),
Field::inst( 'learning_event.other' ),
Field::inst( 'learning_event.modified' ),
Field::inst( 'learning_event.modified_by' )->setValue( $user),
Field::inst( 'learning_event.unit_group_fk' )
->options( Options::inst()
->table( 'unit_group' )
->value( 'unit_group_pk' )
->label( 'unit_group' )
->where( function ($q) {
$q->where( 'unit_group.type', 'learning_event' );
})
),
Field::inst( 'unit_group.unit_group' )
)
->leftJoin( 'unit_group', 'unit_group.unit_group_pk', '=', 'learning_event.unit_group_fk' )
->join(
Mjoin::inst( 'program_outcome' )
->link( 'learning_event.learning_event_pk', 'learning_event_program_outcome_lookup.learning_event_fk' )
->link( 'program_outcome.program_outcome_pk', 'learning_event_program_outcome_lookup.program_outcome_fk' )
->order( 'program_outcome.program_outcome asc' )
->fields(
Field::inst( 'program_outcome_pk' )
->options( Options::inst()
->table( 'program_outcome' )
->value( 'program_outcome_pk' )
->label( array('type', 'program_outcome') )
->render( function ( $row ) {
return $row['type'] . ' - ' . $row['program_outcome'];
} )
->order( 'type' )
),
Field::inst( 'program_outcome' )
)
)
->join(
Mjoin::inst( 'presentation' )
->link( 'learning_event.learning_event_pk', 'learning_event_presentation_lookup.learning_event_fk' )
->link( 'presentation.presentation_pk', 'learning_event_presentation_lookup.presentation_fk' )
->order( 'presentation.presentation_name asc' )
->fields(
Field::inst( 'presentation_pk' )
->options( Options::inst()
->table( 'presentation' )
->value( 'presentation_pk' )
->label( 'presentation_name' )
),
Field::inst( 'presentation_name' )
)
)
->join(
Mjoin::inst( 'mcondition' )
->link( 'learning_event.learning_event_pk', 'learning_event_mcondition_lookup.learning_event_fk' )
->link( 'mcondition.mcondition_pk', 'learning_event_mcondition_lookup.mcondition_fk' )
->order( 'mcondition.mcondition_name asc' )
->fields(
Field::inst( 'mcondition_pk' )
->options( Options::inst()
->table( 'mcondition' )
->value( 'mcondition_pk' )
->label( 'mcondition_name' )
),
Field::inst( 'mcondition_name' )
)
)
->join(
Mjoin::inst( 'learning_event_type' )
->link( 'learning_event.learning_event_pk', 'learning_event_type_lookup.learning_event_fk' )
->link( 'learning_event_type.learning_event_type_pk', 'learning_event_type_lookup.learning_event_type_fk' )
->order( 'learning_event_type.learning_event_type_name asc' )
->fields(
Field::inst( 'learning_event_type_pk' )
->options( Options::inst()
->table( 'learning_event_type' )
->value( 'learning_event_type_pk' )
->label( 'learning_event_type_name' )
),
Field::inst( 'learning_event_type_name' )
)
)
->validator( function ( $editor, $action, $data ) {
if ( $action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT ) {
foreach ( $data['data'] as $pkey => $values ) {
if ( $values['learning_event.low_vision'] !== '2' ) {
return 'Low vision is not 2';
}
}
}
} )
->process($_POST)
->json();
This question has an accepted answers - jump to answer
Answers
Client Side:
What I am wanting to do is sum the values of certain drop-down select lists and if the total is greater than 10, show a message to the user and restrict creation and edit until the issue is fixed.
The select lists for this are:
The way PHP parses such input parameters is as a nested array. So to address this, use:
Allan