Authentication using Codeigniter

Asked

Viewed 516 times

-1

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

In the view, I have 2 presses, 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 the two methods, login and registration

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

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

But I don’t know how to call the right methods, IE, login when I fill in the login and registration fields when I fill in the registration fields. Can someone help me?

2 answers

3


Let’s assume that your controller file calls "user.php"

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 recover the fields with:

$_POST['nome_do_campo'];

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

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.