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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:23:35+00:00 2026-05-15T14:23:35+00:00

I am trying to implement form validation using cakephp models. Here are my code

  • 0

I am trying to implement form validation using cakephp models. Here are my code snippets…

Model

// File: /app/models/enquiry.php
class Enquiry extends AppModel {
    var $name = "Enquiry";
    var $useTable = false;
    var $_schema = array(
        "name"      => array( "type" => "string", "length" => 100 ), 
        "phone"     => array( "type" => "string", "length" => 30 ), 
        "email"     => array( "type" => "string", "length" => 255 )
    );
    var $validate = array(
    'name' => array(
        'rule' => 'notEmpty',
        'required' => true,
        'message' => 'Name is required'
    ),
    'email' => array(
        'emailFormat' => array(
            'rule' => 'notEmpty',
            'required' => true,
            'message' => 'Email is required'
        ),
        'emailNeeded' => array(
            'rule' => array('email', true),
            'required' => true,
            'message' => 'Must be a valid email address'
        )
    )
    );
}

Controller action

// /app/controllers/nodes_controller.php
class NodesController extends AppController {

    var $name = "Nodes";
    var $uses = array( "Enquiry" );
    function enquire() {
        if ( $this->data ) {
           $this->Enquiry->set( $this->data );
            if ( $this->Enquiry->validates() ) {
            // .....
            } else {
                 $this->set("errors", $this->Enquiry->invalidFields());
            }
        }
    }
}

View….

// /app/views/nodes/enquire.ctp
<?php echo $form->create("Node", array("action" => "ask")); ?>
<?php echo $form->input("name", array(
                            "error" => array( "class" => "error-message" ),
                            "div" => false,
                            "label" => "Name",
                            "size" => "40"
                        ) ); ?>
<?php echo $form->input("email", array(
                            "error" => array( "class" => "error-message" ),
                            "div" => false,
                            "label" => "Email",
                            "size" => "40"
                        ) ); ?>
<?php echo $form->input("phone", array(
                            "label" => "Phone No.",
                            "div" => false,
                            "size" => "30"
                        ) ); ?>
<?php echo $form->end("Send");?>

My Problem: On submitting, the form validation occurs, the Model->validates method returns false, but the validation errors never get displayed. I have checked the array returned by invalidFields(), all the error messages I set in the model are there, but they are not getting displayed….

What am I doing wrong?

Regards

  • 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-15T14:23:35+00:00Added an answer on May 15, 2026 at 2:23 pm

    For me the problem is in your form tag.

    Basically if you validating Enquiry, the firm fields should with following names: data[Enquiry][name] instead of data[Node][name].

    If you change

    <?php echo $form->create("Node", array("action" => "ask")); ?>
    

    to

    <?php echo $form->create("Enquiry", array("action" => "ask")); ?>
    

    The errors should appear corectly.

    If your form have mix between Node and Enquiry fields, then just put the name of the Model in front of the field name like this:

    <?php echo $form->input("Enquiry.email", array(....));?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using PHP to implement an HTML form and for validation of the
I am trying to implement client side validation using jquery form validator but I
I am trying to implement a file upload solution using app engine and python.
I've been trying to implement form validation correctly and a discussion on fubu mailing
I am new to WPF and trying to implement validation control on submit form.
I am trying to implement ajax in jsp(avoid form submit) using struts2. I used
I'm trying to implement elegant form validation in a C# / WPF / Entity
I'm trying to implement this method of making a nice form upload: www.kavoir.com/2009/02/styling-file-upload-select-input-control-input-typefile.html/ which
I'm trying to implement a stateful web service in PHP using the SOAP extension.
I'm trying to validate a php register form using valid8 jquery plugin. i need

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.