CodeIgniter Forums

Full Version: should i use redirect or view if validation error exists?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

i have function called register() where it load the view of my registration form,
and the form action is to go to add() function,

inside add() function there's an input validation.
and if there a validation error or message
i redirect it to my register function,

the question is, should i redirect it to register function
or should i use the load->view() to show the form together
with the error message?

i am so confuse ,
please help,

El Forum

Did you use the redirect approach and look at the result? It will not work since the form-validation errors are flash-messages resulting in them being deleted after one request. If you do a redirect you will basically add a second request (submitting the form is request number one) to your request chain thus losing all form-validation errors.

El Forum

hi PhilTem

maybe i will going to use this step,

if registration is failed because of validation error

i will use
to reduce redirect

and if registration successful

i will use redirect,
because if i use
if user refresh the page the post will repeat and the registration
will result to validation error and it will confuse the user.