Editor Validation - Accept only dbValues available in another column
Editor Validation - Accept only dbValues available in another column
How exactly can I define that for 'column_04' (text input) only values available in column_02 (of the database column) ... or empty ('') are valid? Like this?
Editor::inst( $db, 'users' )
->field(
Field::inst( 'users.column_01' ),
Field::inst( 'users.column_02' ),
Field::inst( 'users.column_03' ),
Field::inst( 'users.column_04' )
->validator( 'Validate::dbValues', array(
'field' => 'users.column_02'
'valid' => array(''),
'message' => "Value does not exist!"
) )
)
->process($_POST)
->json();
I'm not exactly sure https://editor.datatables.net/manual/php/validation
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
should be all that is needed.
However there is one very important proviso here - it will check against values which are currently in the database. It will not accept a new value from column 2 that is being submitted at the same time.
For that you would need to use a server-side event to add the validator and add the value from column 2 to the
valid
array.Allan
Thanks Allan. ... plus defining the 'table' like below did the trick in my case ...
And thanks for the hint regarding the additional scenario.
Regards