Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8673065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:21:41+00:00 2026-06-12T19:21:41+00:00

trying to use the beforeSave hook with some server side validation and throwing a

  • 0

trying to use the beforeSave hook with some server side validation and throwing a field error – and it is working ….. kind of ….

There is an exception caused because it doesn’t save as required and the base exception can be viewed with the right message if no field is defined. If I define field then I don’t see the error popup or the error info on the crud form.

To be clear, its not letting me save and throwing the exception. When I use setField('fiscal_year') Its still not saving as per the exception, its just not displaying the exception.

Code below:

class Model_Finances extends Model_Table {
    public $table='finances';

    function init() {
        parent::init();

        $this->hasOne('Grant');

        $this->addField('fiscal_year')->datatype('int');
        $this->addField('requested')->datatype('money');
        $this->addField('committed')->datatype('money');
        $this->addField('spent')->datatype('money');

        $this->getField('grant')->hidden(true);

        $this->addHook('beforeSave',$this);
    }

    function beforeSave($model){
        $exist = $this->api->db->dsql()
                      ->table($this->table)
                      ->field('count(1)')
                      ->where('grant_id', 2) //manually set ID for testing.
                      ->where('fiscal_year', $model['fiscal_year'])
                      ->do_getOne();
        // Validate fiscal year before saving
        if($exist[0]) {
            throw $this->exception('Fiscal year for this grant already exists')->setField('fiscal_year');
        }
    }
}

How it’s being used:

    $finances = $grant->ref('Finances');
    $finances->getField('fiscal_year')->setValueList($this->fiscalYears)->mandatory(true);
    $crud=$tabs->addTab('Finances')->add('CRUD');
    $crud->setModel($finances);
    if($crud->grid)$crud->grid->addTotals(array('requested', 'committed', 'spent'));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:21:43+00:00Added an answer on June 12, 2026 at 7:21 pm

    It was quite difficult to reproduce the problem, so I created a test-case out of it.

    I have changed only this line:

    throw $this->exception('Fiscal year for this grant already exists','ValidityCheck')
        ->setField('fiscal_year');
    

    and here is result

    enter image description here

    • Example: http://test-suite.agiletoolkit.org/?page=issue/so3655
    • Code: https://github.com/atk4/atk4-testsuite/blob/master/page/issue/so3655.php

    If you submit form like this:

    $form->onSubmit(function($f){
        $f->model->blah();
    });
    

    Then exceptions generated inside model->blah will also show up nicely.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying use the new server side plug-in feature for TFS 2010. (I
I'm trying use self-signed certificate (c#): X509Certificate2 cert = new X509Certificate2( Server.MapPath(~/App_Data/myhost.pfx), pass); on
Hi I'm trying use a datepicker on a field I have. I'm trying to
trying to use hibernate with my web app and getting following exception: Initial SessionFactory
I am trying out Castle ActiveRecord. I want to use the Validation features AND
I am trying use javascript regular expressions to do some matching and I found
I'm trying use eco for client-side templating. I have multiple .eco templates that I'd
I am trying use Thread but i have some problem (I am beginner at
I revieving the following error when trying use mysql_real_escape() function Fatal error: Call to
Hi I'm trying use a mixin to define some method using define_method. I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.