Professional Documents
Culture Documents
Praktikum Pertemuan 6
Praktikum Pertemuan 6
<html>
<head>
<title>My Form</title>
</head>
<body>
<h5>Username</h5>
<input type="text" name="username" value="" size="50" />
<h5>Password</h5>
<input type="text" name="password" value="" size="50" />
<h5>Password Confirm</h5>
<input type="text" name="passconf" value="" size="50" />
<h5>Email Address</h5>
<input type="text" name="email" value="" size="50" />
<div><input type="submit" value="Submit" /></div>
</form>
</body>
</html>
formsuccess.php
<html>
<head>
<title>My Form</title>
</head>
<body>
<h3>Your form was successfully submitted!</h3>
Form.php
<?php
if ($this->form_validation->run() == FALSE)
{
$this->load->view('myform');
}
else
{
$this->load->view('formsuccess');
}
}
}
Form.php
<?php
if ($this->form_validation->run() == FALSE)
{
$this->load->view('myform');
}
else
{
$this->load->view('formsuccess');
}
}
}
Form.php (final)
<?php
if ($this->form_validation->run() == FALSE)
{
$this->load->view('myform');
}
else
{
$this->load->view('formsuccess');
}
}
}
2. upload_form.php
<html>
<head>
<title>Upload Form</title>
</head>
<body>
</form>
</body>
</html>
upload_success.php
<html>
<head>
</title>Upload Form</title>
</head>
<body>
<h3>Your file was successfully uploaded!</h3>
<ul>
<?php foreach ($upload_data as $item => $value):?>
<li><?php echo $item;?>: <?php echo $value;?></li>
<?php endforeach; ?>
</ul>
</body>
</html>
Upload.php
<?php
class Upload extends CI_Controller {
public function _construct()
{
parent::_construct();
$this->load->helper(array('form', 'url'));
}
public function index()
{
$this->load->view('upload_form', array('error' => ' ' ));
}
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
}
?>
3. email_form.php
<html>
<head>
<title>CodeIgniter Email Example</title>
</head>
<body>
<?php
if(isset($data)) echo $data;
echo form_open('/Email/send_mail');
?>
<?php
echo form_close();
?>
</body>
</html>
Email.php
<?php
class Email extends CI_Controller {
function _construct() {
parent::_construct();
$this->load->helper('form');
}
public function index() {
$this->load->helper('form');
$this->load->view('email_form');
}
public function send_mail() {
$from_email = "your@example.com";
$to_email = $this->input->post('email');
$this->load->library('email');
if($this->email->send())
$data = "Email sent successfully";
else
$data = "Error in sending Email";
$this->load->view('email_form', $data);
}
}
?>