一个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 代码:
<?phpclass 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文件为添加成功后的显示页面