I am a beginner codeigniter. My purpose is get value from form of example_view.php view, then display this result in the result.php view, when i submitted.
example_view.php(view)
<html>
<head><title>Test Example View</title></head>
<body>
<h1 align="center">Test Sample CI Framwork</h1>
<?php echo form_open('example/getvalue'); ?>
<input type="text" name="username" value="" size="50" />
<div><input type="submit" value="Submit" name="submit"/></div>
<?php echo form_close(); ?>
</body>
</html>
result.php(view)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php echo 'Your new value is '.$value;?>
</body>
</html>
example.php(controller)
<?php
class Example extends Controller {
function Example()
{
parent::Controller();
$this->load->helper('form');
$this->load->helper('url');
}
function index() {
$this->load->view('example_view');
$this->getvalue();
}
function getvalue()
{
if ($this->input->post('submit')==true) {
$data['value']=$this->input->post('username');
$this->load->view('result',$data);
}
}
}
?>
Thank for your help.
=form_input($nm)?> but here its not taking the value of name and id from form_input and not showing it again in form_view in same input box as victor etc so to update and post it back to database...
php class Form_reader extends CI_Controller { public function save_userinput() { //code goes here // for example: getting the post values of the form: $form_data = $this->input->post(); // or just the username: $username = $this->input->post("username"); // then do whatever you want with it :) } } ?>
If you are using form_validation too, you can use
set_value('test'); // $_POST['test']
Otherwise use
$this->input->post('test'); // $_POST['test']
In your form, set something like;
$data = array('name' => 'field' => 'value' => $this->input->post('test'));
echo form_input($data);
To get the value in codeigniter from input you can use post
$this->input->post('name');
You can also get the value from a GET method
$this->input->get('name');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With