php – 如何在点击刷新按钮上重新加载Zend Captcha图像?
发布时间:2020-05-25 10:37:59 所属栏目:PHP 来源:互联网
导读:我在我的php页面中应用了一个Zend验证码,现在我需要添加验证码重新加载按钮.请按照zend给出答案. 只是两个快速的片段,但我想你会得到这个想法.根据需要调整元素名称和选择器. 在控制器中添加一种方法来生成新的验证码 public function refreshAction(){ $form
我在我的php页面中应用了一个Zend验证码,现在我需要添加验证码重新加载按钮.请按照zend给出答案. 只是两个快速的片段,但我想你会得到这个想法.根据需要调整元素名称和选择器. 在控制器中添加一种方法来生成新的验证码 public function refreshAction() { $form = new Form_Contact(); $captcha = $form->getElement('captcha')->getCaptcha(); $data = array(); $data['id'] = $captcha->generate(); $data['src'] = $captcha->getImgUrl() . $captcha->getId() . $captcha->getSuffix(); $this->_helper->json($data); } 在你的视图脚本(我使用mootools为ajax请求) document.addEvent('domready',function() { $$('#contactForm img').addEvent('click',function() { var jsonRequest = new Request.JSON({ url: "<?= $this->url(array('controller' => 'contact','action' => 'refresh'),'default',false) ?>",onSuccess: function(captcha) { $('captcha-id').set('value',captcha.id); $$('#contactForm img').set('src',captcha.src); } }).get(); }); }); 编辑:添加pahan的jquery $(document).ready(function() { $('#refreshcaptcha').click(function() { $.ajax({ url: '/contact/refresh',dataType:'json',success: function(data) { $('#contactForm img').attr('src',data.src); $('#captcha-id').attr('value',data.id); } }); }); }); (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |