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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:40:25+00:00 2026-06-17T09:40:25+00:00

Using CakePHP 1.3 I developed engine for blog with posts and comments tables and

  • 0

Using CakePHP 1.3 I developed engine for blog with posts and comments tables and recently I have noticed that in database I’ve got records with null values in content column despite of the fact that Comment model has defined proper validation:



    <?php
    class Comment extends AppModel {
        var $name = 'Comment';
        var $sequence = 'comments_seq';

        var $belongsTo = array(
            'Post' => array(
                'className'  => 'Post',
                'foreignKey' => 'post_id'
            )
        );

        var $validate = array(
            'content' => array(
                'required' => array (
                        'rule' => 'notEmpty',
                        'message' => 'Content can't be empty.'
                )
            ),
            'post_id' => array(
                'rule' => 'notEmpty'
            ),
            'created' => array(
                'rule' => 'notEmpty'
            )
        );
    ?>

Is there a bug in CakePHP framework or validation defined above is not correct or insufficient?

  • 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-17T09:40:26+00:00Added an answer on June 17, 2026 at 9:40 am

    In your validation rules, you’re not actually requiring the field. Requiring means that the key must exist when it comes time to validate. The notEmpty rule requires only that the key is not empty but not that it exists.

    To require that the field exists, use the required option in your validation rules:

    var $validate = array(
      'content' => array(
        'required' => array ( // here, 'required' is the name of the validation rule
          'rule' => 'notEmpty',
          'message' => 'Content can\'t be empty.',
          'required' => true // here, we say that the field 'content' must 
                             // exist when validating
        )
      ),
      'post_id' => array(
         'rule' => 'notEmpty'
       ),
       'created' => array(
         'rule' => 'notEmpty'
       )
    );
    

    Without the required key, you could potentially save completely empty records by simply not including the ‘content’ key when saving. Now that it is required, validation will fail if ‘content’ is not in the data that you’re saving.

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

Sidebar

Related Questions

Im using cakephp 2.0 and i have data submitted that i want to cleanup,
I recently read that php applications can be deployed on Google App Engine using
I have project developed using cakephp 1.3 and for testing I used SQL Inject
Im using cakePHP 2.2.1 I have a GoalsController that has an add action in
I have developed a CakePHP application that does basic CRUD on a series of
I'm using cakephp 2.1.3 and I have a table Ingredients and a table IngredientAliases
I've used CakePHP on several projects in the past, and have more recently started
Using CakePHP 1.3, I have the following layout: /srv/www/_cakephp13/ /app/ /cake/ /plugins/ /vendors/ etc...
I have kind of an unique situation. I have developed a cakephp app and
I got an old running project that was developed with HTML, CSS, PHP, MySQL,

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.