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

  • SEARCH
  • Home
  • 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 6251453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:37:04+00:00 2026-05-24T13:37:04+00:00

I’ve looked at loads of forums about validation errors not showing and tried various

  • 0

I’ve looked at loads of forums about validation errors not showing and tried various things but to no avail…

Basically, the validation is correctly recognising the fields do not have values when they should, however the error messages don’t ‘automagically’ appear below the input boxes.

Model validation rule is shown below:

var $validate = array(
    'description' => array(
        'rule' => 'notEmpty',
        'required' => true,
        'allowEmpty' => false,
        'message' => 'Please enter a description of the change'
    )
);

echo pr($this->data); output is shown below:

Array
(
[Change] => Array
    (
        [0] => Array
            (
                [id] => 3237
                [cn_id] => 5132
                [req_id] => 25
                [description] => 
            )

        [1] => Array
            (
                [id] => 3238
                [cn_id] => 5132
                [req_id] => 22
                [description] => 
            )

        [2] => Array
            (
                [id] => 3239
                [cn_id] => 5132
                [req_id] => 4
                [description] => 
            )

    )

)

echo pr($this->Change->invalidFields()); output is shown below:

Array
(
[0] => Array
    (
        [description] => Please enter a description of the change
    )

[1] => Array
    (
        [description] => Please enter a description of the change
    )

[2] => Array
    (
        [description] => Please enter a description of the change
    )

[description] => Please enter a description of the change
)

So, it is generating the errors messages for display, but they don’t actually display in the view, and I don’t know why?

Excerpt from the ‘view’ code is show below:

<?php echo $form->input('Change.'.$i.'.description', 
array('value' => $cn['Change'][$i]['description'],
    'label' => $engReq['Req']['description'])); ?>  

Does anybody have ideas why the error messages are not showing?

  • 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-05-24T13:37:05+00:00Added an answer on May 24, 2026 at 1:37 pm

    I experienced the same issue with a hasMany model (where the form had numerically indexed fields) and came up with a validation solution that worked for me.

    Quick answer: Before trying to actually save the data, I validated the data separately like (notice ‘validate’=>’only’):

    if($this->ModelName->saveAll($this->data, array('validate' => 'only'))) {
      // proceed to save...
    }
    

    Doing it this way gave me the model’s validation error message in the form, right under the input field that failed the validation (the normal Cake way of showing the validation error).


    Note: I could not use saveAll() to actually save my data (I’ll explain why in a minute). If I could use saveAll() to actually save the data, I could have gotten the validation at the same time as I saved by using (notice ‘validate’ => ‘first’):

    if($this->ModelName->saveAll($this->data, array('validate' => 'first'))) 
    

    However, I could not use saveAll() to actually save the data, due to the fact that I needed to use a transaction to save several models at once, where some of the models were not directly related to other models. saveAll() will only save the model on which it is called, plus models directly related to it. Since Cake does not currently support nested transactions, and saveAll() uses one transaction automatically, I had to use save() on my models and start and end my transaction manually. However, this caused me to loose the validation message in my form on the hasMany items, even if I saved by using “$this->ModelName->save($this->data, array(‘validate’=>’first’)”.


    Further explanation: The issue does seem to be related to using numerically indexed fields in the form. For example:

    $this->Form->input("ModelName.0.field_name");
    

    It seems this indexing scheme is the proper way to handle hasMany items in the form, but the validation messages would not find their way to this form input. It is interesting to notice that my view did in fact have access to the validation error. This can be seen in the view by using (notice no numerical index in these lines):

    if($this->Form->isFieldError("ModelName.field_name")) {
      echo $this->Form->error("ModelName.field_name");
    }
    

    Putting these lines after the ‘$this->Form->input(“ModelName.0.field_name”)’ inserted a the validation message into the page, just not in the same div as the input field (and thus it didn’t look ideal).

    I couldn’t figure out a way to tell Cake to use that validation message in the ‘$this->Form->input(“ModelName.0.field_name”)’. So I resorted to the ‘validate’ => ‘only’ method described earlier, which is working well for me.

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

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT

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.