CakePHP guaranteeing true validation every time

Hey everyone, I'm relatively new to cakePHP and I've been struggling with a simple user registration feature. For the past two days, I've been stuck on validating the form. No matter what, the validation function always returns true, which means that even if the form is empty, it still gets saved to the database.

I've provided the model, controller, and view below. Can anyone spot any mistakes or suggest any fixes?

/app/Model/MemberModel.php

<?php
class Member extends AppModel {
    var $validate = array(
        "username" => array(
            "rule" => "alphaNumeric",
            "allowEmpty" => false
        )
    );
}
?>

/app/Controller/MemberController.php

<?php
class MemberController extends AppController {

    var $components = array("Security");
    var $helpers = array("Html", "Form");

    public function index() {
    }

    public function register() {

        if($this->request->is("post")) {
            Security::setHash("blowfish");
            $this->Member->set($this->request->data);

            debug($this->Member->validates());

            if($this->Member->save(array("password" => Security::hash($this->request->data["Member"]["password"])))) {
                $this->Session->setFlash(__("Saved."));


    } else {
            $this->Session->setFlash(__("Error: ").$this->validationErrors);
        }
    }
}
}
?>

/app/View/Member/register.ctp

<?php
echo $this->Form->create("Member");
echo $this->Form->input("username");
echo $this->Form->input("password");
echo $this->Form->end("Register");
?>

Answer №1

Aha! I've just realized what's causing your issue.

The problem lies in the following file: <code>/app/Model/MemberModel.php

It should actually be:

/app/Model/Member.php

In order to resolve this, make sure that the controller is looking for the correct file name - Member.php. If it can't find it, then it will fallback to using the default $validate behavior defined in AppModel.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

updating each row in a mysql table

Hey there, I'm facing a bit of a challenge and could really use some help. I've created a table using Bootstrap v4 to display products along with relevant data. In each row, there are buttons - a green one with a pencil icon that redirects me to ...

Creating evenly spaced PHP-generated divs without utilizing flexbox

My goal is to display images randomly from my image file using PHP, which is working fine. However, I am facing an issue with spacing the images evenly to fill the width of my site. This is how it currently appears: https://i.stack.imgur.com/AzKTK.png I ...

Enhanced Slider Display featuring Multiple Posts for Improved Performance

My Sample Page features a slider that displays over 200 posts, each containing 5 images. However, the slider loads all the images at once, causing my page speed to be very slow. I am looking for an optimized way to display the slider without compromising l ...

Sending data to a method in a controller through an ajax request

I am struggling to find the answer, even though it may seem easy. The method in my controller is defined as follows: public function update_news($newsID = NULL) { //updates news article } I am attempting to use this method as the URL in an AJAX call. Fo ...

Using Laravel: accessing parent controller methods in a view

In my setup, I have a main controller named Controller.php that loads various classes. Additionally, I have another controller called Admin.php which extends from the main controller, allowing it to access methods from the loaded classes such as the sessio ...

ListView Adapter fails to display Android TimeStamp values

Whenever my ListView refreshes or reloads, the timestamp is consistently showing as Jan 17, 1970. Why does this keep happening? The value of my timestamp 1441339200 = 2015-09-04 Snippet of code for the timestamp CharSequence timeAgo = DateUtils ...

What is the best way to send a JSON string from a Corona SDK app to a PHP server?

I'm in the process of building an app with Corona SDK. I'm facing an issue where I am sending null values to a mySQL server even though the variable on the app side has a value in the form of a json string. The php code works fine for entering da ...

Service resolution to a factory is not working properly; have you double-checked that it was properly provided during configuration?

I am facing an issue and need some assistance. I have been using the factory template, connecting everything in the configs within the factory itself through the container and returning it to the class. However, I am receiving the error message "Unable to ...

Tips for deleting HTML tags from a database

Whenever I add something to my database, it also includes the html tags. Is there a way to prevent this from happening? public function retrieveDataFromDatabase() { $query = "SELECT * FROM gb ORDER BY id DESC LIMIT 0, 4"; //data output if ...

Is it possible for a cronjob to run continuously for a span of 30 minutes?

Recently, I developed a PHP script that generates cache files from an API. Unfortunately, the process takes about 30 minutes to complete loading all the necessary files for the page. I reached out to my hostinger's customer support team who advised m ...

Incomplete Website Encryption Alert

Currently, I am developing a website called "usborroe.com" and have just set up a GeoTrust Business ID SSL Certificate. However, despite my efforts to ensure full encryption on the site, an error message is indicating that it is not fully encrypted and t ...

Identifying browsers with Zend Framework versus JavaScript

Currently, I am working on developing an application that demands the capability to upload large files. After much consideration, I have opted to utilize the FormData object as it allows me to provide progress updates to the user. Sadly, Internet Explorer ...

Guide on deploying a Symfony application automatically using GitLab CI on a private server

After discovering gitlab-ci to automate my development tasks, I successfully set up a "test" stage for running unit tests. Everything was working perfectly until I hit a roadblock: I wanted to automatically deploy to my dedicated server upon MR approval. ...

What is the standard size for PHP files, or the suggested maximum limit?

I created a tool at where users can upload a .php file with comments and spaces, and it will compress it for a smaller file size. It functions similar to but is web-based and provides instant results. Once you click upload, you receive a prompt to downl ...

Employ fwrite function to generate a Markdown file

Is there a way to utilize the fwrite() function to generate an .md file? I am in the process of developing a blog for a team that requires the ability to upload content without manual typing. The content is structured in markdown format within an .md file ...

Maximizing Server Efficiency with PHP Functions

Suppose I have the code snippet below: <?php function someFunction() { //many lines of code } if ($someBooleanVariable) { //random code here } else { someFunction(); } ?> Query 1: Is it accurate to assume that the server will first lo ...

Guide to redirecting on click when utilizing an iframe

I needed to prevent the page from reloading before the action was complete by using an iframe. However, I encountered an issue where I needed the page to refresh after the action took place. I attempted two methods to achieve this - refreshing the page and ...

Run PHP to secretly initiate a hyperlink

Let me describe my situation for you... I have a link that, when executed in a web browser, sends a message to certain recipients. However, for my website, I need this link to be executed in PHP so that I can retrieve the member's name from the databa ...

Building a website on Netlify using CURL in PHP

Currently, I am utilizing curl commands to fetch information about the sites on my netlify account. However, as per the API documentation, I should also be able to create a site using POST method. Unfortunately, I am encountering an issue where after runni ...

Automatically generate PHP Komodo getter and setter methods

Is there a feature in Komodo that allows for automatic generation of getter/setter methods similar to those found in NetBeans or Eclipse? If so, how can I access and utilize this feature? It seems to be elusive in my search. ...