Welcome Guest, Not a member yet? Register   Sign In
codeigniter form validation and redirect, how could I repopulate the data?
#1

[eluser]searain[/eluser]
In the samples of the user guide.

Success or fail, the "form" controller loads the different view.

But what I want to use is this way.

1) the current controller "form" will submit to another controller.
2) in that controller, I would do the form validation.
3) if validation fail, redirect back to the previous controller, "form".

This way, I have two issues.

1) first the error message display, I would need to use set_flashdata to pass the validation errors.

But
2) how could I repopulate the the form data if when fail I redirect it back to the previous controller, "form"? use session?



Thanks!
#2

[eluser]RedIgniter[/eluser]
just change the <form action=""> action link to the controller you want the validation to take place, and check if $this->form_validation->run() == FALSE then redirect back to the page the form is.
#3

[eluser]searain[/eluser]
Yeah. My question is how to repopulate the data if I redirect it back to the page the form is. the default way to repopulate the data is the for the form and validation controller using the same controller.
#4

[eluser]RedIgniter[/eluser]
By saying repopulate you mean the values inside the input boxes so the users won't have to type in again?
#5

[eluser]searain[/eluser]
yes.
#6

[eluser]RedIgniter[/eluser]
hmm probably with set_value?
#7

[eluser]InsiteFX[/eluser]
Why not just create a method in a library then you have
access to it anywhere?

InsiteFX
#8

[eluser]Nisha S.[/eluser]
It is possible if you save the post array to a session before the redirect and restore it from session to $_POST array in the second controller before using the set_value method. But redirect on failure of form validation doesn't look a good way. Just do all in one controller as a best practice.




Theme © iAndrew 2016 - Forum software by © MyBB