0

So, i have 2 forms, one is for sign up, and another is for sign in

<div class="row">
<div class="col-md-6">
    <h3>Sign Up</h3>
    <form action="{{ route('signup') }}" method="post">
        <div class="form-group">
            <label for="email">Your E-Mail</label>
            <input class="form-control" type="email" name="su_email" id="email">
        </div>
        <div class="form-group">
            <label for="first_name">First Name</label>
            <input class="form-control" type="text" name="first_name" id="first_name">
        </div>
        <div class="form-group">
            <label for="password">Password</label>
            <input class="form-control" type="password" name="su_password" id="password">
        </div>
        {{ csrf_field() }}
        <button class="btn btn-primary">Submit</button>
    </form>
</div>
<div class="col-md-6">
    <h3>Sign In</h3>
    <form action="{{ route('signin') }}" method="post">
        <div class="form-group">
            <label for="email">Your E-Mail</label>
            <input class="form-control" type="email" name="si_email" id="email">
        </div>
        <div class="form-group">
            <label for="password">Password</label>
            <input class="form-control" type="password" name="si_password" id="password">
        </div>
        {{ csrf_field() }}
        <button class="btn btn-primary">Submit</button>
    </form>
</div>

Here is my controller

public function postSignUp(Request $request)
{
    $email = $request['su_email'];
    $first_name = $request['first_name'];
    $password = bcrypt($request['su_password']);

    $user = new User();
    $user->email = $email;
    $user->first_name = $first_name;
    $user->password = $password;
    $user->save();
    return redirect()->back();
}
public function postSignIn(Request $request)
{
    if (Auth::attempt(['email' => $request['si_email'], 'password' => $request['si_password']])) {
        return view('dashboard');
    }
    return redirect()->back();
}

So the problem is: when i enter values in "sign in" form, and then go back to page, in my "first_name" field i have "si_email" value, and in "su_password" i have "si_password" value

Why this happens? I didnt set any value in my html.

4
  • What do you mean by and then go back to page? Was there a redirect happening somewhere in between? Commented Sep 2, 2016 at 20:47
  • I think this is a browser thing. When you go back you get populated fields as they were. With the exception of passwords. Commented Sep 2, 2016 at 20:47
  • @lesssugar i just go to myapp.host manually, or if i enter bad email-password, i redirect()->back and still get bad values in sign-up form Commented Sep 2, 2016 at 21:03
  • @RomanGanoshenko As for the bad input part, did you try redirect()->back()->withInput()? This should keep the original input in case of failed validation. Commented Sep 2, 2016 at 21:07

1 Answer 1

1

I can't say for sure, but I think it's because the id's are the same on certain inputs. The id attribute should always br unique. It is possible that when the old input is being returned that it is returning it to the wrong id.

Edit

I think you have a syntax error here as well,it might not be whats causing the problem, but it should still be fixed:

if (Auth::attempt(['email' => $request['si_email'], 'password' => $request['si_password']]) {

If you are wondering what the difference is, i removed a bracket from the end.

Sign up to request clarification or add additional context in comments.

2 Comments

no, i changed to all unique ids - still the same problem. and the problem isn't in chrome, installed firefox, use valid email and password to login form, and after go back to myapp.app/, my form have these email-pass in sign-in form and in "first_name"-"password" of sign-up ;(
Is everything getting inserted into thr database properly?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.