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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:36:58+00:00 2026-06-11T17:36:58+00:00

I have a view file that looks like this: <?php echo $this->Form->create(‘ModelName’); echo $this->Form->input(‘ModelName.0.firstField’);

  • 0

I have a view file that looks like this:

<?php
    echo $this->Form->create('ModelName');
        echo $this->Form->input('ModelName.0.firstField');
        echo $this->Form->input('ModelName.0.secondField');
        echo $this->Form->input('ModelName.1.firstField');
        echo $this->Form->input('ModelName.1.secondField');
    echo $this->Form->end();
?>

My question is, how do I validate this data? I’m not saving, so it seems pointless to me to call the save or saveAll methods. I just want to validate the data before I process it and display the results to the user.

What happens currently using:

<?php
    if ($this->request->is('post')) {
        $this->ModelName->set($this->request->data);
        if ($this->ModelName->validates()) {
            echo $this->Session->setFlash('Success');
        } else {
            echo $this->Session->setFlash('Failure');
        }
    }
?>

Is it succeeds all the time even when I’m putting in data that should definitely fail.
I have also tried:

<?php
    if ($this->request->is('post')) {
        if ($this->ModelName->validateMany($this->request->data)) {
            echo $this->Session->setFlash('Success');
        } else {
            echo $this->Session->setFlash('Failure');
        }
    }
?>

And that return success all the time as well, but that may be due to the fact that I don’t know how to properly use validateMany.

  • 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-11T17:36:59+00:00Added an answer on June 11, 2026 at 5:36 pm

    Model::set is used for assigning a single set/record of data to the current instance of the Model. So it may be possible that you are only validating the first set of data in your POST data. You would have to iterate through each record in the POST data, Model::set it to the Model data, and then call Model::validates.

    Instead of the above method or Model::validateMany, try using Model::saveAll without actually saving.

    http://api20.cakephp.org/class/model#method-ModelsaveAll

    validate: Set to false to disable validation, true to validate each record before saving, ‘first’ to validate all records before any are saved (default), or ‘only’ to only validate the records, but not save them.

    <?php
        if ($this->request->is('post')) {
            if ($this->ModelName->saveAll($this->request->data, array('validate' => 'only'))) {
                echo $this->Session->setFlash('Success');
            } else {
                echo $this->Session->setFlash('Failure');
            }
        }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .php file that looks like this: foreach($stmt->fetchAll() as $array) { echo
I have a view that I'm loading, and my onCreate() method looks like this:
I have a local sqlite database file that looks something like this… _ID |
i have a URL that looks like this ......index.php?option=com_jumi&fileid=8&Itemid=34 i know that i can
I have a list view that looks like this and that's its code ..
Let's say I have a PHP Model-View-Controller framework that maps an address like http://example.com/admin/posts/edit/5
I have a view_mine_and_others.php file that outputs this html <div class=rec id=1> <div class=val>343</div>
I have a renderer that looks like this: <s:ItemRenderer xmlns:fx=http://ns.adobe.com/mxml/2009 xmlns:s=library://ns.adobe.com/flex/spark xmlns:mx=library://ns.adobe.com/flex/mx autoDrawBackground=true> <s:Group
Title says all. I'll have navigation that looks like this and it's dynamically created
My current .htacces file looks like this: DirectoryIndex index.php RewriteEngine on RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico)

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.