Custom Error Message

Custom Error Message

map@odenterprise.orgmap@odenterprise.org Posts: 14Questions: 4Answers: 0

Hello,

I am trying to give a custom error message in the editor while using the 'Validate::dbValues' validator. It is still showing the
"A system error has occurred (More information)" Error message.

Here is my code -

Field::inst( 'org_profiles.industry_id' )
                ->validator( 'Validate::dbValues', array( 'message' => "Value not valid!" ) ),

Thanks for the help! :)

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    edited May 2017

    Mis-read the question. Sorry.

  • allanallan Posts: 63,889Questions: 1Answers: 10,530 Site admin

    That error means that valid JSON is not being returned from the server. Have a look with your browser's developer tools to see what is actually being sent back. Likely there is an error message stating what is going wrong.

    Allan

  • map@odenterprise.orgmap@odenterprise.org Posts: 14Questions: 4Answers: 0

    Thanks for the replies. I just realised that my code is giving an error when I use ->validator( 'Validate::dbValues'). The staff.php in the network tab of the console shows the following error even when I enter a value which is present in the database. This is the error -

    Fatal error: Call to a member function table() on a non-object in /var/www/html/survey/templates/dbadmin/Datatables-editor/php/Editor/Validate.php on line 931

    Line 931 is

        $table = $cfg['table'] ? $cfg['table'] : $options->table();
    

    Could you please help me solve this? Thanks!

  • allanallan Posts: 63,889Questions: 1Answers: 10,530 Site admin
    Answer ✓

    Could you add a table option into the array where you are currently passing in the custom message please? It should be the table that you want to check the value against. You might also need to have a field property for the column.

    Allan

  • map@odenterprise.orgmap@odenterprise.org Posts: 14Questions: 4Answers: 0

    Hi Allan,

    Thanks for the solution. I have made the following change and it works perfectly. Even the custom message is being displayed.

            Field::inst( 'org_profiles.industry_id' )
                    ->validator( 'Validate::dbValues' , array( 'table' => 'org_profiles',
                        'field' => 'industry_id',
                        'message' => "Value not valid!" ) ),
    

    Thanks a ton for the excellent support! :)

This discussion has been closed.