Validate::dbValues syntax

Validate::dbValues syntax

LapointeLapointe Posts: 430Questions: 81Answers: 4
Field::inst( 'clients.CodePostal' )
// Run OK
    ->validator( 'Validate::dbValues', array( 'table' => 'communes', 'column' => 'CodePostal', 'message' => 'un code postal valide est requis' ) )
// don't run
    ->validator(
        Validate::dbValues( ValidateOptions::inst()
               ->table( 'communes' )
               ->column( 'CodePostal' )
            ->message( 'un code postal valide est requis' )
        )
    )
    ->setFormatter( 'Format::ifEmpty', null )
,

Where is the problem ?

Thanks

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,348Questions: 36Answers: 394

    What does "don't run" mean? What happens? Do you see any error message? What debugging have you done?

  • LapointeLapointe Posts: 430Questions: 81Answers: 4

    hi @tangerine
    Yes I get
    DataTables warning: table id=CliTbl - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

    Fatal error: Uncaught Error: Call to undefined method DataTables\Editor\ValidateOptions::table()

    Writing this make me see there is not options defined...

    trying

                            ->validator(Validate::dbValues()
                                    ->table( 'communes' )
                                    ->column( 'CodePostal' )
                                    ->message( 'un code postal valide est requis' )
                                )
    

    is not better
    just DataTables warning: table id=CliTbl - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

  • kthorngrenkthorngren Posts: 20,292Questions: 26Answers: 4,768

    Did you follow the steps at the link in the error?
    http://datatables.net/tn/1

    Let us know what you find.

    Kevin

  • LapointeLapointe Posts: 430Questions: 81Answers: 4

    Hi Kevin

    Yes I did but
    using

     Field::inst( 'clients.CodePostal' )
        ->validator(Validate::dbValues()
             ->table( 'communes' )
             ->column( 'CodePostal' )
            ->message( 'un code postal valide est requis' )
        )
        ->setFormatter( 'Format::ifEmpty', null )
    ,
    

    breakpoint at validate.php line 1012...

    public static function dbValues( $cfg=null, $column=null, $table=null, $db=null, $values=array() ) {
        $opts = ValidateOptions::select( $cfg );
            
        return function ( $val, $data, $field, $host ) use ( $opts, $column, $table, $db, $values ) {
    

    trying to go in step by step crash (get no answer at all)...

  • LapointeLapointe Posts: 430Questions: 81Answers: 4

    Hi @kthorngren @allan

    As discussed, dbValues validator does not run using syntax as:

         ->validator(
            Validate::dbValues( ValidateOptions::inst()
                   ->table( 'tbl' )
                   ->column( 'Col' )
                    ->message( 'Msg' )
            )
        )
    

    Only ->message is accepted to work with dbValues
    I think it is an error from me, but...

    Using this syntax

    ->validator( 
        'Validate::dbValues', array( 'table' => 'tbl', 'column' => 'Col', 'message' => 'Msg' ) )
    

    run correctly

    Do you know where I'm wrong ?

    Please let me know...

    Regards
    Bob

  • allanallan Posts: 61,686Questions: 1Answers: 10,100 Site admin
    Answer ✓

    Hi Bob,

    The syntax being used there is wrong - you need to pass the table / column information into the dbValues() function (see the source):

        Validate::dbValues(
            ValidateOptions::inst()->table( 'tbl' ),
            'col',
            'tbl'
        )
    

    Allan

This discussion has been closed.