发新话题
打印

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

本主题由 Hex 于 2008-2-18 10:27 移动

[1.5.4]一个 Form_Mail 的例子

一个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 .= "$valuen";
  }
 
  $message = "$fname ($email) would like to register for the following lees:n$lees and had this to say:nn$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>;Please 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>;Please select one or more seminars, that you would like to attend</p>
  <p><?php echo form_checkbox($purpose); ?> <label for="purpose">;Purpose of Prayer</label></p>
  <p><?php echo form_checkbox($prepare); ?> <label for="prepare">;Prepare for Prayer</label></p>
  <p><?php echo form_checkbox($principles); ?> <label for="principles">;Principles of Prayer</label></p>
  <p><?php echo form_checkbox($power); ?> <label for="power">;Power 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文件为添加成功后的显示页面
附件: 您所在的用户组无法下载或查看附件

TOP

发新话题