Authentication using CodeIgniter

-2

I'm starting to use codeigniter, and I have a question.

In the view, I have 2 forms, one for login and one for registration:

<form id="login" method="post">
    <legend>Login</legend>
    <p><label>email:</label> <input type="email"/></p>
    <p><label>senha:</label> <input type="password"/></p>
    <p><label>enviar</label> <input type="submit"/></p>
</form>

<form id="cadastro" method="post">
    <legend>Cadastro</legend>
    <p><label>nome:</label> <input type="text"/></p>
    <p><label>email:</label> <input type="email"/></p>
    <p><label>senha:</label> <input type="password"/></p>
    <p><label>Repita a senha:</label> <input type="password"/></p>
    <p><label>enviar</label> <input type="submit"/></p>
</form>

And in the controller, I have both methods, login and register

public function login(){
    echo 'chamou login';
}

public function cadastro(){
    echo 'chamou cadastro';
}

But I do not know how to call the right methods, that is, login when I fill in the login and registration fields when I fill in the registration fields. Can anyone help me?

    
asked by anonymous 28.12.2015 / 16:11

2 answers

2

Let's assume your controller file calls "user.php"

It would look like this:

<form id="login" method="post" action="http://www.seudominio.com.br/index.php/user/login/">
<legend>Login</legend>
<p><label>email:</label> <input type="email"/></p>
<p><label>senha:</label> <input type="password"/></p>
<p><label>enviar</label> <input type="submit"/></p>

<form id="cadastro" method="post" action="http://www.seudominio.com.br/index.php/user/cadastro/">
    <legend>Cadastro</legend>
    <p><label>nome:</label> <input type="text"/></p>
    <p><label>email:</label> <input type="email"/></p>
    <p><label>senha:</label> <input type="password"/></p>
    <p><label>Repita a senha:</label> <input type="password"/></p>
    <p><label>enviar</label> <input type="submit"/></p>
</form>

Ready, now inside your controller you can retrieve the fields with:

$_POST['nome_do_campo'];

Remember that your input must contain an attribute called "name" to return via POST.

    
28.12.2015 / 16:40
0

You can also use the codeigniter helper form and call the post like this:

$this->load->helper('form');  
$email = $this->input->post('email');

Reference: link

    
31.12.2015 / 18:14