Welcome Guest, Not a member yet? Register   Sign In
How can I post back login form data to controller to verify it in database?
#1

[eluser]manojchakri[/eluser]
Hi all,
My view is a login form with
Code:
<html>
<head>
<title>My Form</title>
</head>
<body>

<h5>Username</h5>
&lt;input type="text" name="username" value="uname" size="50" /&gt;

<h5>Password</h5>
&lt;input type="password" name="password" value="pwd" size="50" /&gt;

&lt;input type="submit" value="Submit" /&gt;&lt;/div>

&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
And my controller is
class Form extends Controller
{
function index()
{
$this->load->view('forms_view');
}
}
Now How can I post the data from the login form fields to the same or another controller for checking with the database.I was not able to understand the explanation in user manual.Any body please provide sample code.Thanks in advance.
#2

[eluser]gtech[/eluser]
in your form tag you direct the url to the controller..

I have used site_url() which is gathered from you config.php file settings using 'base_url' and 'index_page'... to create a string similar to 'http://localhost/CI/index.php'

forms view ('/form/post_method' will call the post_method in the form controller)
Code:
&lt;form method="post" action="&lt;?=site_url()?&gt;/form/post_method"&gt;
  &lt;input type="text" name="username" value="uname" size="50" /&gt;
&lt;/form&gt;

then in the form controller
Code:
class Form extends Controller
{
  function index()
  {
    $this->load->view('forms_view');
  }
  function post_method()
  {
    $username = $this->input->post('username');
    echo $username;
  }
}
#3

[eluser]manojchakri[/eluser]
Thank you very much for your reply.Now I want to build a model which will take username as input and verify the same in database.How can I do that.Please provide sample code.pleeeese.I tried but I am unable to send the data to the model.How can I send that?
#4

[eluser]gtech[/eluser]
[url="http://ellislab.com/codeigniter/user-guide/general/models.html"]Read the models section in the userguide[/url]

model
Code:
class User_model extends Model {

    function User_model()
    {
        parent::Model();
    }
    funtion test($param1)
    {
      echo $param1;
    }
}

controller
Code:
...
$this->load->model('User_model');
$this->User_model->test('hello world');
...

have fun, you should be able to find loads of examples on the forums, I would suggest you follow the screen cast tutorials off the codeigniter home page.. there are tonns of resources or even google for a tutorial.
#5

[eluser]manojchakri[/eluser]
Tahnk you very much for your support. Your answers were very helpful
#6

[eluser]gtech[/eluser]
your welcome.




Theme © iAndrew 2016 - Forum software by © MyBB