|
楼主 |
发表于 2011-6-17 20:53:35
|
显示全部楼层
我摘片段:
Control:
$this->load->library('email');
$this->load->library('form_validation');
$this->form_validation->set_message('required', $tip_required.':%s');
$this->form_validation->set_message('valid_email', $tip_email);
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
$this->form_validation->set_rules('topic', $topic, 'trim|required');
$this->form_validation->set_rules('name', $yourname, 'trim|required');
$this->form_validation->set_rules('email','E-mail', 'trim|required|valid_email');
$this->form_validation->set_rules('im', 'MSN/QQ', 'trim|required');
$this->form_validation->set_rules('address', $address, '');
$this->form_validation->set_rules('tel', $tel, 'trim|required');
$this->form_validation->set_rules('contents', $contents, 'required');
$this->form_validation->set_rules('captcha', $tip_captcha, 'required|callback_captcha_check');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('template/sendmail',$data);
}
else
{//mail使用163.com发邮件,略
$this->load->view('template/sendmail_ok',$data);
}
function captcha_check($str)
{
if (strtolower(trim($str)) != $_SESSION['captcha'])
{
$this->form_validation->set_message('captcha_check', '%s');
return false;
}else
{
return true;
}
}
+++++++++++++++
View:
<script>
function onsub(){
$('#sub').attr("disabled",true);
}
</script> <form method="post" action="">
E-mail:<input name="email" type="text" id="email" size="40" value="<?php echo set_value('email');?>" /><input style="border: 1px solid #ddd;background-color: #fefefe;width:200px" type="text" name="captcha" id="captcha-form" value="" /><br />
<a class=redfont href="#" style="text-decoration:none;" onClick="
document.getElementById('captcha').src='<?=base_url()?>public/js/captcha/captcha.php?'+Math.random();
document.getElementById('captcha-form').focus();"
id="change-image"><img src="<?=base_url()?>public/js/captcha/captcha.php" id="captcha" /><input id='sub' class='commentbu' type='submit' value='Submit' onclick='onsub()' />
<input type='reset' name='button' id='button' value='Reset'></form>
+++++++
我是多语言后台的,代码我尽量简化了。 |
|