Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Check out some of the field
  • I have a User model has a validation method


    $val->add_callable('\Rules');

    $val->add('username', 'Username')
    ->add_rule('required')
    ->add_rule('trim')
    ->add_rule('strip_tags')
    ->add_rule('min_length', 3)
    ->add_rule('max_length', 20)
    ->add_rule('valid_string', array('alpha', 'numeric'))

    ->add_rule('unique','users.username');

    ........

    etc.


    there are still some fields that the user fills

    How do I make such a check if the user wants to change my username or email, not all fields are checked

    if ($val->run(null, true))
    {
      echo 'Success';
    }
    else
    {
    \Session::set_flash('error', $val->error());
      }

    The field Username must be unique, but LOGIN has already been used

    How do I ignore the Username field if the input data does not differbut to some other field tested method of validation

  • For validation it shouldn't be a problem that some fields are not changed, they will contain the old values, which will be validated without problems (as they were validated earlier).

    As for unique, maybe this will help: http://fuelphp.com/forums/discussion/comment/11841

  • I think it is not safe to rely on the hidden id field in the form

    I wanted to do something like this


    public function action_account()
    {
    \Sentry::check() or \Response::redirect('/');

    try
    {
    $user = \Sentry::getUser();
    $val = Model_User::validate('edit');



    if ($user->username == \Input::post('username'))
    {
     need to remove the value of   \Input::post();  with a key  username
    }

    //  Is there any way to do this?

  • You can also store it in the session, then it's server side, and it can not be tampered with.

    If you don't want to validate the entire form, you can pass an array to $val->run(), just get Input::post(), remove username if it wasn't changed, and pass the rest on.
  • can cause a small example of how to check the field username, but do not check it if it is not changed
  • HarroHarro
    Accepted Answer
    Personally, I would do something like:

    if ($user->username == \Input::post('username'))
    {
        $val->delete_rule('unique');
    }

    so, if it isn't changed, don't run the unique rule.
  • Thanks, that's what you need

    $val->field('username')->delete_rule('unique');

  • Ah, yeah, oops. forget the field()...

Howdy, Stranger!

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

In this Discussion