Better way to validate user input in cakephp I'm trying to find a way to make my code easeier to read, so i found that major part of the code is validation trough if, ifelse:

    if (!$this -&gt; is_valid_username($username)) {
        $this -&gt; Session -&gt; setFlash('Enter valid client username, Error 1.', 'default', array(), 'errorlogaddclient');
        $this -&gt; redirect('/dashboard/settings');
        exit ;
    }
    if (!$this -&gt; is_valid_password($password) || !$this -&gt; is_valid_defpass($password)) {
        $this -&gt; Session -&gt; setFlash('Enter valid password, Error 2.', 'default', array(), 'errorlogaddclient');
        $this -&gt; redirect('/dashboard/settings');
        exit ;
    }
    if ($this -&gt; is_already_client($user)) {
        $this -&gt; Session -&gt; setFlash("User is already someone's client, Error 3", 'default', array(), 'errorlogaddclient');
        $this -&gt; redirect('/dashboard/settings');
        exit ;
    }//ect


so what is proper/better way to do this
I would split up the code into objects, with good object oriented patterns. This should result in objects that have very distinct responsibilities.

The pattern I think you should primarily look into is the "Proxy" pattern (See "Design Patterns" book by "Gang of four".) It can be used to extract the code that ensures security, for example. It makes the security code independent from the domain logic / data access / user interface. 

It may mean refactoring a lot of code, but once done, you can then write thorough unit-tests for the security proxy in isolation, giving you a rock solid foundation.

Write tests, then write the testable code, (i.e. isolated) then refactor to the point where it's neat and tidy.