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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:56:15+00:00 2026-06-01T15:56:15+00:00

I have only recently started using CakePHP and have been unable to get validation

  • 0

I have only recently started using CakePHP and have been unable to get validation to work in a contact app that I have created for the sole purpose of testing forms. Once I setup the $validate array in the modal, the asterisks showed up on the form, however, I still am not getting the validation messages when I submit the form. Here is my code:

/app/View/Contacts/index.ctp

<h1>Contact Form</h1>
<?php
echo $this->Form->create('Contact');
echo $this->Form->input('name');
echo $this->Form->input('age');
echo $this->Form->end('Submit This Form!!!');
?>

/app/Controller/ContactsController.php

<?php
    class ContactsController extends AppController {

    public $helpers = array('Html', 'Form');

    public function index() {

    }
}
?>

/app/Model/Contact.php

<?php
class Contact extends AppModel {
    var $useTable = false;

    public $validate = array(
        'name' => array(
            'rule' => 'notEmpty',
            'message' => 'Cannot leave this field blank.'
        ),
        'age' => array(
            'rule' => 'notEmpty',
            'message' => 'Cannot leave this field blank.'
        )
    );
}
?>
  • 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-01T15:56:16+00:00Added an answer on June 1, 2026 at 3:56 pm

    Your mistake is probable in the code you DIDN’T show us:
    How you process your form data in the controller.
    You probably forgot to set the data to the model.

    Take a look on this tutorial here:
    http://www.dereuromark.de/2011/12/15/tools-plugin-part-2-contact-form/

    My guess looking at your empty (!) index action.
    You are not doing anything at all. How should that trigger the validation?

    I refer to the above link. It shows you how you can validate such a form using set() and validates().
    Basically it boils down to:

    if ($this->request->is('post') || $this->request->is('put')) {
        $this->ContactForm->set($this->request->data);
        if ($this->ContactForm->validates()) {
        }
    }
    

    PS: and since “contacts” is not really a word here and doesnt mean what is supposed to mean I suggest you rename your controller to “ContactController”. which also makes the url /contact

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

Sidebar

Related Questions

I have recently started using automapper and it has work fine for me so
I've just recently started using VS2008 for a new tools project, and have been
I have recently started using VirtualBox to get my Linux environment rather than fully
I have only recently started web programming and I am pretty much amazed that
I recently started using Eclipse at work for my Java servlet projects. I've been
Recently I have started using Lucene. However, after few days I've spotted that queries
I've only just started using Castle Windsor recently and have a question. Suppose I
I have only fairly recently started using Maven (2.2.1), and I have Artifactory running
I have only recently started working with the MVC approach, so I suppose this
I honestly have only started recently researching this so my knowledge is limited. I

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.