Validate on database using dbValues
Validate on database using dbValues
I am trying to validate a customer number on the customer table. As far as I can read on this forum This should be the correct validator:
Field::inst( 'analysis.customer')
->validator( 'Validate::dbValues', array(
'table' => 'customer',
'field' => 'number',
'message' => 'My error message'
)),
Uncaught Error: Call to a member function value() on null in /var/www/html/weight/php/Editor/Validate.php:
This question has an accepted answers - jump to answer
Answers
I am trying to validate a customer number on the customer table. As far as I can read on this forum This should be the correct validator:
Field::inst( 'analysis.customer')
->validator( 'Validate::dbValues', array(
'table' => 'customer',
'field' => 'number',
'message' => 'My error message'
)),
however I get this error server side:
Uncaught Error: Call to a member function value() on null in /var/www/html/weight/php/Editor/Validate.php:
joining the tables with an option works:
Field::inst( 'analysis.customer')
->options( Options::inst()
->table( 'customer')
->value( 'number')
->label( 'name')
)
->validator( 'Validate::dbValues', array(
'message' => 'My error message',
) ),
But this is not convenient, as I will then be sending the large customer base to the client. Any clues to why the first solution is not working?
Try this:
Using
dbValues
as a string name function is the old way of doing (although it should work still, so I'll look into that). The documentation here shows the full function signature.Allan
Working fine with above validator, I will use new notatino going forward,
Thank you Allan,