Yet another validation question |
[eluser]yello[/eluser]
Hi! I am building some kind of social networking website right now and I am having this dilema: my urls look like this: domain.com/browse/state/city/username each username has a form on their page so people can send them message... i'm trying to set simple validations on each of the profile's pages... Code: function send() Since it is not a 'static' form with a static url/view, I don't know how to redirect the user on the correct user profile if their is an error in the validation process. Can someone help me on this one? Thanks!
[eluser]danoph[/eluser]
replace Code: if ($this->validation->run() == FALSE) with Code: if ($this->validation->run() == FALSE)
[eluser]charlieD[/eluser]
If you include the URL helper, you can use the following to redirect a user within your application. Code: //Load URL helper; this includes the redirect() function
[eluser]yello[/eluser]
charlieD, I have used your method but it seems that the "<?=$this->validation->error_string; ?>" does not work... any idea why? Code: <? $this->load->view('includes/header'); ?>
[eluser]danoph[/eluser]
You should only redirect the user if all of the information is correct. If there is an error when a user is filling out a form and you redirect them, none of the validation data will be saved. Here is an example of a controller function that handles a form submission (login form): Code: function login($data = array()) { This is an example from my EzAuth model I released about a week ago.
[eluser]yello[/eluser]
The thing is that I use a view which used by tens of profiles... how to send back the user to the profile page with the validation errors activated? It is not a static view like a login view, it is a form that is used to send the profile's owner an email on his profile page.
[eluser]danoph[/eluser]
That's fine, just load the view or call the function inside the controller that loads the view, for example: Code: $this->load->view('profile_view'); or Code: $this->profile(); Both will save the validation data and display the error string, validation field data and messages, etc. If you use a redirect, they are all erased!
[eluser]yello[/eluser]
The controller that sends the email and the controller that outputs the profile view are diffrent... is that a problem? Profile Controller: Code: function profile() Email controller Code: function send()
[eluser]danoph[/eluser]
based on your email controller, you are redirecting to the browse function if there is an error? You should just load that view or call that function in the controller. Then it will save all of the validation data.
[eluser]yello[/eluser]
I understand what you mean... but they are two diffrent controllers! I can't just do $this->profile() since #1: It will not find the profile() function, #2: It won't keep the correct URI and without that, it won't send the user back to the correct profile page |
Welcome Guest, Not a member yet? Register Sign In |