Welcome Guest, Not a member yet? Register   Sign In
Do you know withInput() and Validation errors?
#1

(This post was last modified: 08-17-2022, 05:16 AM by kenjis.)

redirect()->withInput() and Validation errors have an undocumented behavior.

If you redirect with withInput():
PHP Code:
if (! $this->validate($rules)) {
    return redirect()->back()->withInput();

https://github.com/kenjis/ci4-validation...hp#L53-L55

You can use the Validation object with the validation errors in the previous page.
PHP Code:
<?= service('Validation')->listErrors() ?>
https://github.com/kenjis/ci4-validation...rm2.php#L7

But this feature has bugs or design flaw.
So I would like to remove the feature, and add a new helper function to get the validation errors.

Any opinion?
Reply
#2

(This post was last modified: 08-16-2022, 11:57 PM by luckmoshy.)

Yes even I was been asking myself such a thing but I neglected to pursue a query !!! ???
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply
#3

Sounds great to me.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

@luckmoshy What do you mean?
Have you ever used the feature?
Reply
#5

(This post was last modified: 08-18-2022, 07:11 PM by luckmoshy.)

@kenjis of cause at earlier from CI 4.0 I didn't know what to do with redirect withinput back and get a specific error because of  CI documentation The global return
PHP Code:
redirect()->back()->withInput(); 
  was not shown any specific errors result method or how to get a specific error or succeeded reply from failed action query. So when you call this action, I totally agree with you that we should have errors resulting from the helper function than using a 
PHP Code:
<?= service('Validation')->listErrors() ?>
(validation) service in view or  Angel look we see we can get an errors to list ok and how about succeded result ?? or  Rolleyes is it formed for only errors result???!!!

@kenjis  I truly have been using this  global CI
PHP Code:
redirect()->back()->withInput(); 
  with additional fourth session methods like 
PHP Code:
redirect()->back()->withInput()->with('danger/*success*/',/*In modal*/$this->modal->errors() /*or something else apart with modal */); 
and then
PHP Code:
session()->get('danger/*success*/'); / 
in a view

but I may have a view of the point that it could be good if you design a new helper function and may have a specific single error validation result perimeter or with multiple validations on its parameter something like that or  this
PHP Code:
redirect()->back()->withInput(); 

in  additionally, Why this
PHP Code:
redirect()->back()->withInput(); 
if you have an app with a bulk of routes with
Code:
routes priority
it redirects back to an unintended route  so it's forcedly me to use
PHP Code:
redirect()->to(current_url())->withInput(); 
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply
#6

(This post was last modified: 08-31-2022, 01:23 AM by kenjis.)

The undocumented redirect()->withInput() and Validation errors behavior was treated as a bug.
It won't work, so do not use it.

Since v4.3, you can use Form helper validation_list_errors() (and validation_errors(), validation_show_error()).
See https://github.com/kenjis/ci4-validation...rm2.php#L7
Reply
#7

Added explanation to README.
https://github.com/kenjis/ci4-validation...ial#readme
Reply
#8

Thank you @kenjis
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB