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 6714313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:28:53+00:00 2026-05-26T08:28:53+00:00

I have a form that collects information from several models that are several layers

  • 0

I have a form that collects information from several models that are several layers apart in their association. For that reason, I have to save each individually and, if any fail, report back to the view so that error messages can be displayed. Because of the sequential saves, I assume, any errors aren’t appearing correctly, nor am I finding that the isFieldError() method is catching the existence of the error.

Any idea how I can access this data at the view level to check for an error? I’d like to validate all 3 models so I can display all errors at the same time and also avoid creating a manual data structure and testing for that. Is there native Cake functionality/data that I can access so this isn’t a completely custom solution that I can’t use in more traditional instances?

# Controller snippet
if( $this->Proposal->Requestor->saveField( 'phone_number', $this->data['Requestor']['phone_number'] ) && $this->Proposal->Requestor->Building->saveAll( $this->data ) ) {
  # Save off the proposal and message record.
  exit( 'saved' );
}      
else {
  $this->Session->setFlash( 'We can\'t send your quote just yet. Please correct the errors below.', null, null, 'error' );
  # At this point, I may have 2 or more models with validation errors to display
}

# Snippet from an element loaded into the view
# $model = Requestor, but the condition evaluates to false
<?php if( $this->Form->isFieldError( $model . '.phone_number' ) ): ?>
  <?php echo $this->Form->error( $model . '.phone_number' ) ?>
<?php endif; ?>

Thanks.

  • 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-26T08:28:54+00:00Added an answer on May 26, 2026 at 8:28 am

    This is the magic of open source software. A little digging around in the source code showed me that $this->Form->isFieldError ultimately reads from a view variable named $validationErrors. When doing my independent saves, I just write to a local variable by the same name in my controller action and set it out manually. Thus the unconventional process is mapped to conventional results and the view code doesn’t need to recognize any kind of custom structure.

    # Compile our validation errors from each separate
    $validationErrors = array();
    if( !$this->Proposal->Requestor->validates( array( 'fieldList' => array_keys( $this->data['Requestor'] ) ) ) ) {
      $validationErrors['Requestor'] = $this->Proposal->Requestor->validationErrors;
    }
    if( !$this->Proposal->Requestor->Building->saveAll( $this->data ) ) {
      $validationErrors = Set::merge( $validationErrors, $this->Proposal->Requestor->Building->validationErrors );
    }
    
    if( empty( $validationErrors ) ) {
      # TODO: perform any post-save actions
    }
    else {
      # Write the complete list of validation errors to the view
      $this->set( compact( 'validationErrors' ) );
    }
    

    If there’s a better way to do this, someone please let me know. For the moment, at least, this seems to be doing the right thing.

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

Sidebar

Related Questions

I have a form that collects information, one piece of which is a phone
I have a web form that collects information and submits it to a cgi
Background, Part 1 I have a form that collects both frequency and duration from
I have a form that collects a data using ASP.NET MVC. It looks like
Let's say I have a form that collects a first name and a last
I have a website form that collects url of users to store in a
I have form that displays several keywords (standard set of choice lists that changes
I have an online form which collects member(s) information and stores it into a
I have a form that collects 4 pieces of info. My goal is to
I have some information which gets passed from a form and needs to be

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.