To create form in codeigniter, codeigniter provide us a function to create form that is very secure for us.
First Load Form Helper
$this->load->helper('form');
Use this code in your webpage
echo form_open('email/send');
this code create html form where action is email/send.
This code create form tag in your page, you can view source code
Controller
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class User extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->helper('url');
$this->load->helper('form');
}
public function index()
{
$this->load->view('test');
}
}
View
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<html>
<head></head>
<body>
<?php
echo form_open('user/input');
echo form_input('username', '');
echo form_submit('btnsubmit','Submit');
echo form_close();
?>
</body>
</html>
<?php
echo form_open('email/send', 'class="email" id="myform"');
echo form_close();
?>
Output
<form action="http://localhost/codeigniter/index.php/email/send" class="email" id="myform" method="post" accept-charset="utf-8">
</form>
<?php
echo form_open_multipart('email/send', 'class="email" id="myform"');
echo form_close();
?>
Output
<form action="http://localhost/codeigniter/index.php/email/send" class="email" id="myform" enctype="multipart/form-data" method="post" accept-charset="utf-8">
</form>
<?php
echo form_open_multipart('email/send', 'class="email" id="myform"');
$data = array(
'name' => 'Shishir Developer',
'email' => 'shishirdeveloper@gmail.com',
'url' => 'http://shishirdeveloper.com'
);
echo form_hidden($data);
echo form_close();
?>
Output
<form action="http://localhost/codeigniter/index.php/email/send" class="email" id="myform" enctype="multipart/form-data" method="post" accept-charset="utf-8">
<input type="hidden" name="name" value="Shishir Developer" />
<input type="hidden" name="email" value="shishirdeveloper@gmail.com" />
<input type="hidden" name="url" value="http://shishirdeveloper.com" />
</form>
form_password()
form_upload()
form_textarea()
form_dropdown()
form_multiselect()
form_checkbox()
form_radio()
form_submit()
form_reset()
form_button()
form_close()