EllisLab text mark
Advanced Search
     
should i use redirect or view if validation error exists?
Posted: 02 November 2012 02:50 AM   [ Ignore ]
Joined: 2012-09-16
4 posts

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,
thanks

 
Posted: 02 November 2012 08:19 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2011-02-23
882 posts

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.

 Signature 

ignited Community Framework (WiP)  |  Read the User’s Guide. It won’t bite.

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

CI example .htaccess

 
Posted: 02 November 2012 12:45 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2012-09-16
4 posts

hi PhilTem

maybe i will going to use this step,

if registration is failed because of validation error

i will use

$this->load->view() 

to reduce redirect

and if registration successful

i will use redirect,
because if i use

$this->load->view() 

if user refresh the page the post will repeat and the registration
will result to validation error and it will confuse the user.