0

我有一个有验证的 cakephp 表单。验证本身有效,但是当单击提交后出现错误时,它只会产生一些文本。

为什么我没有颜色。例如,它的意思是用红色显示错误。

控制器

    <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>

模型

    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 回答 2

1

您是否在 default.ctp 中包含样式表?如果您从 default.ctp 布局中删除了默认的 CakePHP 样式表,则默认颜色将不再存在。

您需要在布局中再次包含 CakePHP 样式表(在这里您可以看到它在原始 default.ctp 中的情况:https ://github.com/cakephp/cakephp/blob/master/app/View/Layouts/default .ctp#L33 )

或者在样式表中创建自己的 CSS 样式。您可以使用默认 CakePHP 样式表中的样式作为示例;

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

于 2013-03-07T21:20:15.957 回答
0

您的代码没有任何问题。这就是 CakePHP 处理错误报告的方式。红色的东西是为缺少视图、缺少功能或无法连接到数据库等重大错误保留的。基本上会生成 400 范围内的状态代码的东西。

我做了一些搜索以更好地回答你的问题,但我偶然发现了这个页面。 CakePHP 2.0 - 如何制作自定义错误页面?

当你做错事时,CakePHP 会生成什么状态码。我认为验证错误甚至会抛出 OK (200) 但不会向数据库写入任何内容。在我身上发生了几次。

于 2013-03-07T17:49:32.297 回答