用户
 找回密码
 入住 CI 中国社区
搜索
查看: 5042|回复: 2
收起左侧

[其它 Other] [1.5.4]一个 Form_Mail 的例子

[复制链接]
发表于 2008-2-5 18:36:55 | 显示全部楼层 |阅读模式
一个Form_Mail的例子,第一次做,做得不好,请大家评评!
说明:该例子使用了rewrite,请将apache的rewrite模块打开,

请先打开system\application\config目录下config.php文件更改其它项目:

$autoload['libraries'] = array('email');
$autoload['helper'] = array('url','form');
system\application\controllers目录下form.php文件内容为:
PHP复制代码
<?php
class Form extends Controller
{
 function index()
 {
  #input and textarea field attributes
 $data['fname'] = array(
   'name' => 'fname'
   ,'id' => 'fname'
   );
  $data['email'] = array(
   'name' => 'email'
   ,'id' => 'email'
   );
  $data['comments'] = array(
   'name' => 'comments'
   ,'id' => 'comments'
   );
 
  #Checkbox attributes
 $data['purpose'] = array(
   'name' => 'lee'
   ,'id' => 'purpose'
   );
  $data['prepare'] = array(
   'name' => 'lee'
   ,'id' => 'prepare'
   );
  $data['principles'] = array(
   'name' => 'lee'
   ,'id' => 'principles'
   );
  $data['power'] = array(
   'name' => 'lee'
   ,'id' => 'power'
   );
 
  $this ->load ->view('form_view',$data);
 
 }
 
 function submit()
 {
  $fname = $this->input->post('fname');
  $email = $this->input->post('email');
  $comments = $this->input->post('comments');
  $lees = "";
 
  foreach($this->input->post('lee') as $value){
   $lees .= "$value\n";
  }
 
  $message = "$fname ($email) would like to register for the following lees:\n$lees and had this to say:\n\n$comments";
  $this->email->from($email, $fname);
  $this->email->to('vaysalee@gmail.com');
  $this->email->subject('Lee Registration');
  $this->email->message($message);
  $this->email->send();
 
  $this->load->view('form_success');
 }
 
 /* function blog()
 {
  $this->load->model('Blogmodel');
  $data['query'] = $this->Blogmodel->get_last_ten_entries();
  $this->load->view('blogview',$data);
 } */

 
}
?>
复制代码


system\application\views目录下的form_view.php的内容为

HTML复制代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="content-type" c />
<title>Godbit Code Igniter Tutorial: Creating a simple Registration Form</title>
<style type="text/css">
body {
 font: small/1.5em Verdana, Arial, Helvetica, serif;
}
</style>
</head>
<body>
  <h1>Registration Form</h1>
  <p>lease complete the following form:</p>
  <?php echo form_open('form/submit'); ?>
  <p><label for="fname">Full Name: </label><br /><?php echo form_input($fname); ?></p>
  <p><label for="email">E-mail: </label><br /><?php echo form_input($email); ?></p>
  <p>lease select one or more seminars, that you would like to attend</p>
  <p><?php echo form_checkbox($purpose); ?> <label for="purpose">urpose of Prayer</label></p>
  <p><?php echo form_checkbox($prepare); ?> <label for="prepare">repare for Prayer</label></p>
  <p><?php echo form_checkbox($principles); ?> <label for="principles">rinciples of Prayer</label></p>
  <p><?php echo form_checkbox($power); ?> <label for="power">ower in Prayer</label></p>
  <p><label for="comments">Comments: </label><br /><?php echo form_textarea($comments); ?></p>
  <?php echo form_submit('submit', 'Submit'); ?>
  <?php echo form_close(); ?>
  <p><label>RunTime{elapsed_time}</label></p>
</body>
</html>
复制代码


system\application\views目录下的form_success.php文件为添加成功后的显示页面

CII.rar

330 KB, 下载次数: 57

发表于 2009-2-11 16:36:13 | 显示全部楼层
顶一下,楼主辛苦
发表于 2009-4-9 17:52:21 | 显示全部楼层
foreach($this->input->post('lee') as $value){
   $lees .= "$valuen";
  }

红色的地方是写错了 还是故意的?
没看懂

本版积分规则