dongliang9682 2013-03-19 23:21
浏览 14
已采纳

cakephp未按预期验证模型

not sure what i'm doing wrong, re-read the documentation several times. this is the only time i've tried to validate a model from an outside controller though. it processes as if the validation went through fine, even when i use an invalid email address though. only the recaptcha works; any help would be greatly appreciated:

in the controller:

if(!$this->request->is('get'))
{
    App::import('Vendor','recaptchalib');
    $this->set('captchaContent' , recaptcha_get_html($this->publicKey));
    $resp = recaptcha_check_answer( $this->privateKey, 
        $_SERVER['REMOTE_ADDR'],
        $this->request->data['recaptcha_challenge_field'],
        $this->request->data['recaptcha_response_field']);          
    if (!$resp->is_valid) {
        $this->set('recaptcha_error','You did not enter the words correctly. Please try again.');
    } elseif($this->Support->validates($this->request->data)) {
        // send the message
    }
}

in the model:

class Support extends AppModel
{
    public $name = 'Support';
    public $useTable = false;   
    public $validate = array(
        'email' => array('rule'=>'email','message'=>'You must enter a valid email')
        );
}

in the view:

echo $this->Form->create('Support');
echo $this->Form->input('name');
echo $this->Form->input('email');
echo $this->Form->input('message',array('type'=>'textarea'));
echo '<div style="margin-left: 150px; margin-bottom: 10px;">'.$captchaContent.'</div>';
if($recaptcha_error) echo '<p style="color:red; margin-left: 150px;">'.$recaptcha_error.'</p>';
echo $this->Form->end('Send Message');
  • 写回答

2条回答 默认 最新

  • dongti7838 2013-03-19 23:40
    关注

    found the problem, needed to put

    $this->Support->set($this->request->data);
    

    before the validation call, apparently a controller not accessing its own model needs to have this explicitly set. thanks anyway :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?