0

I have a cakephp form that has validation. The validation itself works BUT when an error shows up after clicking submit, it just produces some text.

Why am I getting no colour. eg Its meant to display errors in red.

Controller

    <div class="users form">
            <?php echo $this->Form->create('Ticket'); ?>
                <fieldset>
                    <legend><?php echo __('Purchase'); ?></legend>



                        <?php
                            echo $this->Form->input('first_name');
                            echo $this->Form->input('last_name');
                            echo $this->Form->input('email');
                            echo $this->Form->input('phone');
                            echo $this->Form->input('date', array('options'=> $dates));
                            echo $this->Form->input('quantity', array('options' => $maxAmount, 'default' => '1'));
                        ?>
                </fieldset>
                    <?php   
                        echo $this->Form->end(__('Purchase')); 
                    ?>
            </div>

Model

    public $validate = array(
    'first_name' => array(
        'rule'     => '/^[a-zA-Z]{1,}$/i',
        'message'  => 'Alphabets only',
        'required' => true
    ),
    'last_name' => array(
        'rule'     => '/^[a-zA-Z]{1,}$/i',
        'message'  => 'Alphabet only',
        'required' => true
    ),
    'phone' => array(
        'rule'     => 'numeric',
        'message'  => 'numbers only please',
        'required' => true
    ),
    'email' => array(           
        'rule'    => 'email',
        'message' => 'Your email is not valid',
        'required' => true

    ),
    'quantity' => array(
        'rule'     => 'numeric',
        'message'  => 'numbers only please',
        'required' => true
    )
);
4
  • 2
    Have you styled your error class ? To make it display in red ? Commented Mar 7, 2013 at 16:48
  • 1
    "Its meant to display errors in red." - where is the code to tell it to be red? Commented Mar 7, 2013 at 17:30
  • In this case, PHP code is not as interesting as the resulting HTML and its associated CSS. Commented Mar 7, 2013 at 17:41
  • cake done it before i made a default.ctp file. How can i achieve red errors? Commented Mar 7, 2013 at 17:48

2 Answers 2

1

Did you include a stylesheet in your default.ctp? If you removed the default CakePHP stylesheet from your default.ctp layout, the default colours will no longer be there.

You need to either include the CakePHP stylesheet again in your layout (here you can see how it was in the original default.ctp: https://github.com/cakephp/cakephp/blob/master/app/View/Layouts/default.ctp#L33)

Or create your own CSS styles in your stylesheet. You can use the styles from the default CakePHP stylesheet as an example;

https://github.com/cakephp/cakephp/blob/master/app/webroot/css/cake.generic.css#L371

Sign up to request clarification or add additional context in comments.

2 Comments

i included it but forgot to add a couple of lines. lol. Sorted now anyway :)
Not to be picky, but based on you comments you marked the wrong answer as the correct one? The other answer was for 'Custom Error Pages'?
0

There is nothing wrong with your code. That is just how CakePHP is handling the error reporting. The red stuff is reserved for major errors like missing view, or a missing function, or cant connect to the database. Basically stuff that would generate a status code that is in the range of 400.

I did some searching to answer your question better, but i stumbled on this page. CakePHP 2.0 - How to make custom error pages?

Its all about what status code CakePHP will generate when u do something wrong. Validation errors will I think throw even an OK (200) but wont write anything to the database. Happened a couple a times to me.

3 Comments

im not wanting an error page.... i just get text below my inputs giving me my error messages. I want these bits of texts to be in red. I have no idea on how to achieve this :(
Ehm, create a CSS style sheet? See the default CakePHP stylesheet for inspiration: github.com/cakephp/cakephp/blob/master/app/webroot/css/…
i am such a noob. lol. i hadn't properly set things in my css file. thanks for the help :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.