0
votes

I am trying to implement "signin or signup" form in codeigniter.so its one form which accepts email and password and POST to below controller.

Expectation : check if email is duplicate, if exists, Post email,password to login method, else post email,password to register method.

Current behaviour: it checks for duplicate and posting validate error as email already exits and never login.

Here is my user controller logic

public function index()
{
  $email = $this->input->post('email');
  $password = $this->input->post('password');
  $this->form_validation->set_rules('email', 'Email', 'is_unique[user.email]');
    if( $this->form_validation->run() === FALSE)
        {
          $this->login($email,$password);

        }
  else { $this->register($email,$password);}
}
1
so you try it with a existing email and it doesn't login. sounds like your problem is with the login() function which isn't here. also typically in ux there is a login page and a sign up page that are separated via link - we don't always want to assume that the user wants to create an account by attempting to login. imagine a scenario, which happens quite often, where a user mistypes or enters the wrong email... i also hope your login() and register() methods are private as they reside in the controller and aren't meant to be used via a url.Alex
Thanks Alex, you raised a valid case of typos , initial idea was to give ux same form email/password for login as well as signup.instead can we use two buttons for same input fields(email and password and submit??) link signin and signup.i mean two action tgt for same form in CI.. some pointer may helpuser4382574

1 Answers

1
votes

As per Alex's comment, using single button will create unwanted user accounts when user typed email address wrong, so we decided to go with 2 submit buttons(signin,signup) for 1 form which is working as expected with minimal effort and clean UX. just formaction html tag will do the trick!!.hope this help someone!

<form class="row" name="regform" action = "<?php echo base_url()?>user/login" method="POST">
            <input type="hidden" name="ref" value=1>
            <div class="col-md-6 col-lg-3"> <input type="email" name="email" placeholder="Email Address"> </div>
            <div class="col-md-6 col-lg-3"> <input type="password" name="password" placeholder="Any Password"> </div>
            <div class="col-md-6 col-lg-3"> <button type="submit" class="btn btn--primary type--uppercase" name="signup" value="signup" formaction = "<?php echo base_url()?>user/register">Signup</button> </div>
            <div class="col-md-6 col-lg-3"> <button type="submit" class="btn btn--primary type--uppercase" name="signin" value="signin" formaction = "<?php echo base_url()?>user/login">Signin</button> </div>
        </form>