I'd like to disable editing or deletion of a record if a certain field is already set in that record.
Looking at the manual here I think this should be possible. I'm thinking of passing in the record's ID to the validation function and then running a sql query to see if the field in question is already set for that record.
However taking the example from the manual
// Create and edit with dependent validation
Editor::inst( $db, 'table' )
->fields( ... )
->validator( function ( $editor, $action, $data ) {
if ( $action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT ) {
foreach ( $data['data'] as $pkey => $values ) {
if ( $values['country'] === 'US' && $values['location'] === 'London UK' ) {
return 'London UK is not in the US';
}
}
}
} )
->process( $_POST )
->json();
if I try to pass in data from the field "tablename.idfieldname" as $values['tablename.idfieldname]
I get the error message "Undefined index: tablename.idfieldname" on an edit attempt.
I think this is because the value "idfieldname" isn't being edited and so isn't being passed in the data. Thus it is undefined. That's if I'm understanding this correctly.
Is there a way (there must be) to extract the the ID of the row being edited?
Many thanks in advance to anyone with the answer!