Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Login Form not working
  • Hello,

    I try to make a login form in a special Template, but this is not working. The page is always reloaded empty ater sending the form. (With my "old" Layout it was working!)

    Here is my code:
    Controller: http://bin.fuelphp.com/snippet/view/r6
    View: http://bin.fuelphp.com/snippet/view/r8

    The dump in line 75 is always visible. It looks as it never hits the validation. Even if I send the Form empty, page is reloaded.

    Hope someone has an idea what I make wrong.

    Thanks
    Kay
  • Obvious next step would then be to dump Input::method(). Does it contain what you expect?
  • Strange, it's:
    (String): "GET" (3 characters)
    Now it's clear why Formis not working.
    But why is this GET???
    And how can I change this?

  • check your form.php config file. I suspect you've changed the "form_method" to "GET".
  • No it's:
        'form_method'                => 'post',

    And HTML Source is:

    <form action="http://playground.local/admin/login" accept-charset="utf-8" method="post">
    <div class="fields">
    <input placeholder="Username" name="username" value="" type="text" id="form_username" />
    <input type="password" placeholder="Password" name="password" value="" id="form_password" />
    <input name="fuel_csrf_token" value="a2ff745b47fc1fabc012ddc8dc708deac22a3050a8efa2e569b76a358280c8ce5a950ded6b90327698e3efbb97ce34c6d1df7bcd2341bb8d99f4642556ca5828" type="hidden" id="form_fuel_csrf_token" />
    </div>
    <a href="#" title="" class="forgot-password">Forgot?</a>
    <button class="btn btn-primary btn-block" name="submit">Sign In</button>
    </form>

    I think the problem is the "button" as it does not fire the form.
  • If it doesn't fire the form, how did you manage to dump the input method then?

    <button> inside a form is interpreted differently by different browsers, it's safer to use a input tag with a type="submit". For a <button> tag to submit, it needs a type attribute too, which seems to be missing.
  • As long as the form is not fired Input::method() is always GET, or?

    I have tried both versions without any luck

    1) Button:
     <?php echo Form::button('submit', 'Sign In', array('class' => 'btn btn-primary btn-block'))."\r\n\t"; ?>
    Which creates:
    <button class="btn btn-primary btn-block" name="submit">Sign In</button>
     2. Input:
    <?php echo Form::input('submit', 'Sign In', array('type' => 'submit', 'class' => 'btn btn-primary btn-block'))."\r\n\t"; ?>
    Which creates:
    <input type="submit" class="btn btn-primary btn-block" name="submit" value="Sign In" id="form_submit" />
    Do you have any other idea why the form is not submitted?
  • the input one should absolutely submit the form. And the rest of your form looks absolutely fine.
  • Mhh crazy.. :-(

    How can I dump if the form was submitted?
    Is it possible to dump the values from the form before sending to controller?
    I need to find out, where it runs into the nirvana... Must be somewhere.

    Here is my controller again: http://bin.fuelphp.com/snippet/view/r-

    In line 76 I'll dump Input::method()which always shows GET.
    In line 80 I assume hat if everything would run correctly dump should show POST.

    If I do that in an other installation before firing the form line 76 shows GET
    and after firing the form line 76 and 80 both show POST.
  • I don't get you. You say that the form doesn't submit.

    So there is nothing to see, no submit means no post means no controller is called... Obviously there's nothing to see then.

    So why doesn't the form submit? Because there doesn't seem to be anything wrong with the form. Are you sure it doesn't submit? Maybe it does but it hits a redirect (which would make it a GET again).
  • You seems to be right Harro, I think the orm is submitted but then something else happens.
    If I click on "submit" the page and the form is reloaded.

    I found it. It's the redirect in line 49 !!!

    The admin controller was created via oil admin scaffolding, so the code is from there...

    Any idea what I can do now?
  • Check if line 36 does what it should.

    That if should bypass the redirect on line 49 if this controller's "login" or "logout" action is called.

    If line 49 is to blame, then something goes wrong there...
  • Hi Harro,

    I tried to set this up one again from the scratch. As long as I use the view created with admin scaffolding, the login in working perfectly.

    When I use my own theme and send the login screen, then I run into an error and get in line 49.

    I have no idea what's the difference as I only change the theme and use another login form. I have not changed anything in the logic n the controller.

    Do you have any idea what could cause this?
    Thanks Kay
  • HarroHarro
    Accepted Answer
    What error? The process flow in the controller isn't altered by using another view.

    In the controller you posted, you only get to that redirect if the request is not for Controller_Admin::login or Controller_Admin::logout, and nobody is logged in.

    So you need to debug those two if statements...
  • There is a javascript in the HTML code of the template saying: document.location = 'dashboard.html'

    Now it is working as expected.
    Thanks alot.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion