Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Fieldset Validation issue
  • Ok, I'm stumped.

    I'm creating a 'change password' for the user; I'm using php8.1 and Fuel version 1.9-dev

    I have no other issues with other parts of my application thus far.

    I've got a fieldset with validation, I'm not generating it from Model\Auth_User because I only need a couple of fields.

    After $form->validation()->run() I have a known error but Session::set_flash('error', e($form->validation()->error())); shows nothing, but if I echo $form->show_errors(); I see my expected errors.

    When I have no validation errors echo $form->show_errors(); shows empty array() and                 if ( ! $form->validation()->error()) fails.

    Fieldset Code:
    $user = Model\Auth_User::find($id);

    $form = \Fieldset::forge('passwordform');
    $form->form()->add_csrf();
    $form->add('username', '', ['type' => 'hidden']);
    $form->add('oldpassword' , 'Old Password', ['type' => 'password'], [['required']]);
    $form->add('newpassword' , 'New Password' , ['type' => 'password'] , [['required'], ['min_length', 8]]);
    $form->add('confirm', 'Confirm New Password', ['type' => 'password' ], [['required'], ['match_field' , 'newpassword']]);
    $form->add('submit', '', array('type' => 'submit', 'value' => 'Update', 'class' => 'btn medium primary'));
    $form->field('username')->set_value($user['username']);


    What am I doing wrong here?
  • HarroHarro
    Accepted Answer
    Your fieldset looks exactly like how I would do it, I don't see any issue with it.

    e($form->validation()->error())

    won't work, becasuse error() returns an array, not a string, even if there is only one error message. So you need to iterate over it to show error messages.

    I have no idea why

    if ( ! $form->validation()->error())

    would fail, as ( ! array() ) evaluates to True, that hasn't changed in PHP 8.1.

  • I changed e($form->validation()->error()) to $form->show_errors() and viola! Fixed that part..

    The real problem was later.

    I had thought that somehow if ( ! $form->validation()->error()) was failing because i wasn't seeing my exception. I realized that I had a typo - SimpleUserUpdaetException so I wasn't seeing the problem.

    Once I fixed that I realized that I was passing arguments into Auth::change_password in the wrong order :facepalm:

    Sometimes the answers are right in front of your face!
  • Good you've got it sorted !

Howdy, Stranger!

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

In this Discussion