How to create a form to take input from user's in CI:-
1:- Create Controller and define index()
2 Create view file and design form for simple interest (3 text field,1 submit button with form tag)
3 write form action with the controller method name
<form action="<?php echo site_url(); ?>/Controllername/methodname" method="post">
</form>
4 load view under index() of controller
5 create an action method to write code on the controller
6 define url helper to use base_url() in application/config/autoload.php
7 set route
Program Code
Controller
<?php
class SI extends CI_Controller
{
function index()
{
$this->load->view('siview');
}
function silogic()
{
//$p= $_POST['txtp'];
//$r= $_POST['txtr'];
//$t =$_POST['txtt'];
$p=$this->input->post('txtp');
$r=$this->input->post('txtr');
$t=$this->input->post('txtt');
$si = ($p*$r*$t)/100;
$data['res']=$si;
$data['p1']=$p;
$data['r1']=$r;
$data['t1']=$t;
$this->load->view('siview',$data);
}
}
?>
View File
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form action="<?php echo site_url(); ?>/si/silogic" method="post">
<input type="text" name="txtp" placeholder="Enter p" value="<?php echo @$p1; ?>" />
<br>
<br>
<input type="text" name="txtr" placeholder="Enter r" value="<?php echo @$r1; ?>"/>
<br>
<br>
<input type="text" name="txtt" placeholder="Enter t" value="<?php echo @$t1; ?>" />
<br>
<br>
<input type="submit" name="btnsubmit" value="Calculate" />
</form>
<?php
echo @$res;
?>
</body>
</html>
Autoload.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| AUTO-LOADER
| -------------------------------------------------------------------
| This file specifies which systems should be loaded by default.
|
| In order to keep the framework as light-weight as possible only the
| absolute minimal resources are loaded by default. For example,
| the database is not connected to automatically since no assumption
| is made regarding whether you intend to use it. This file lets
| you globally define which systems you would like loaded with every
| request.
|
| -------------------------------------------------------------------
| Instructions
| -------------------------------------------------------------------
|
| These are the things you can load automatically:
|
| 1. Packages
| 2. Libraries
| 3. Drivers
| 4. Helper files
| 5. Custom config files
| 6. Language files
| 7. Models
|
*/
/*
| -------------------------------------------------------------------
| Auto-load Packages
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['packages'] = array(APPPATH.'third_party', '/usr/local/shared');
|
*/
$autoload['packages'] = array();
/*
| -------------------------------------------------------------------
| Auto-load Libraries
| -------------------------------------------------------------------
| These are the classes located in system/libraries/ or your
| application/libraries/ directory, with the addition of the
| 'database' library, which is somewhat of a special case.
|
| Prototype:
|
| $autoload['libraries'] = array('database', 'email', 'session');
|
| You can also supply an alternative library name to be assigned
| in the controller:
|
| $autoload['libraries'] = array('user_agent' => 'ua');
*/
$autoload['libraries'] = array();
/*
| -------------------------------------------------------------------
| Auto-load Drivers
| -------------------------------------------------------------------
| These classes are located in system/libraries/ or in your
| application/libraries/ directory, but are also placed inside their
| own subdirectory and they extend the CI_Driver_Library class. They
| offer multiple interchangeable driver options.
|
| Prototype:
|
| $autoload['drivers'] = array('cache');
|
| You can also supply an alternative property name to be assigned in
| the controller:
|
| $autoload['drivers'] = array('cache' => 'cch');
|
*/
$autoload['drivers'] = array();
/*
| -------------------------------------------------------------------
| Auto-load Helper Files
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['helper'] = array('url', 'file');
*/
$autoload['helper'] = array('url');
/*
| -------------------------------------------------------------------
| Auto-load Config files
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['config'] = array('config1', 'config2');
|
| NOTE: This item is intended for use ONLY if you have created custom
| config files. Otherwise, leave it blank.
|
*/
$autoload['config'] = array();
/*
| -------------------------------------------------------------------
| Auto-load Language files
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['language'] = array('lang1', 'lang2');
|
| NOTE: Do not include the "_lang" part of your file. For example
| "codeigniter_lang.php" would be referenced as array('codeigniter');
|
*/
$autoload['language'] = array();
/*
| -------------------------------------------------------------------
| Auto-load Models
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['model'] = array('first_model', 'second_model');
|
| You can also supply an alternative model name to be assigned
| in the controller:
|
| $autoload['model'] = array('first_model' => 'first');
*/
$autoload['model'] = array();
routes.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
| -------------------------------------------------------------------------
| URI ROUTING
| -------------------------------------------------------------------------
| This file lets you re-map URI requests to specific controller functions.
|
| Typically there is a one-to-one relationship between a URL string
| and its corresponding controller class/method. The segments in a
| URL normally follow this pattern:
|
| example.com/class/method/id/
|
| In some instances, however, you may want to remap this relationship
| so that a different class/function is called than the one
| corresponding to the URL.
|
| Please see the user guide for complete details:
|
| https://codeigniter.com/user_guide/general/routing.html
|
| -------------------------------------------------------------------------
| RESERVED ROUTES
| -------------------------------------------------------------------------
|
| There are three reserved routes:
|
| $route['default_controller'] = 'welcome';
|
| This route indicates which controller class should be loaded if the
| URI contains no data. In the above example, the "welcome" class
| would be loaded.
|
| $route['404_override'] = 'errors/page_missing';
|
| This route will tell the Router which controller/method to use if those
| provided in the URL cannot be matched to a valid route.
|
| $route['translate_uri_dashes'] = FALSE;
|
| This is not exactly a route but allows you to automatically route
| controller and method names that contain dashes. '-' isn't a valid
| class or method name character, so it requires translation.
| When you set this option to TRUE, it will replace ALL dashes in the
| controller and method URI segments.
|
| Examples: my-controller/index -> my_controller/index
| my-controller/my-method -> my_controller/my_method
*/
$route['default_controller'] = 'si';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
....................................................................................................................................
Q1 WAP to SWAP TWO NUMBER?
Q2 WAP to CREATE MARKSHEET PROGRAM WHERE SUBJECT NAME and OBTAINED MARKS WILL BE ENTERED BY THE USER.
1 all subject marks should be 0 to 100
2 if only one subject marks are <33 then suppl
3 if the minimum two subject marks are <33 then fail
4 if all subject marks are>33 then % and division should be calculated
5 display distinction subject name
6 display suppl subject name
7 display failed subject name
POST Answer of Questions and ASK to Doubt