Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

PRAKTIKUM PERTEMUAN 6

Andrew Narapati (1911501474)


PRAKTIKUM 6.3
1. myform.php

<html>
<head>
<title>My Form</title>
</head>
<body>

<?php echo validation_errors(); ?>


<?php echo form_open('form'); ?>

<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>

<p><?php echo anchor('form', 'Try it again!'); ?></p>


</body>
</html>

Form.php

<?php

class Form extends CI_Controller {


public function index()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');

if ($this->form_validation->run() == FALSE)
{
$this->load->view('myform');
}
else
{
$this->load->view('formsuccess');
}
}
}
Form.php

<?php

class Form extends CI_Controller {


public function index()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('passconf', 'Password Confirmation',
'required');
$this->form_validation->set_rules('email', 'Email', 'required');

if ($this->form_validation->run() == FALSE)
{
$this->load->view('myform');
}
else
{
$this->load->view('formsuccess');
}
}
}

Form.php (final)
<?php

class Form extends CI_Controller {


public function index()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'required|
min_length[5]max_length[12]|is_unique[users.username]', array('required' => 'You
have not provided %s.', 'is_unique' => 'This %s already
exists.'));
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required|
matches[password]');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email|
is_unique[users.email]');

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>

<?php echo $error;?>


<?php echo form_open_multipart('upload/do_upload');?>

<input type="file" name="userfile" size="20" />

<br /><br />

<input type="submit" value="upload" />

</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>

<p><?php echo anchor('upload', 'Upload Another File!'); ?></p>

</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' => ' ' ));
}

public function do_upload()


{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;

$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');
?>

<input type = "email" name = "email" required />


<input type = "submit" value = "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');

$this->email->from($from_email, 'Your Name');


$this->email->to($to_email);
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');

if($this->email->send())
$data = "Email sent successfully";
else
$data = "Error in sending Email";

$this->load->view('email_form', $data);
}
}
?>

You might also like