Codeigniter using flashdata and form_validation?

If you redirect when a form that posts to itself is valid, then yes you will lose set_value() as there is now nothing in the $_POST array - this is why you redirect, so a user won't resubmit the form on refresh What you should do is create your own validation rule in a callback function in the same controller. See here codeigniter.com/user_guide/libraries/for... What you need to do is pass the email to a model in the callback that will check the email against your database and return false if it is already there. This way, your form will not be valid and not redirect if the email already exists.

If you redirect when a form that posts to itself is valid, then yes you will lose set_value() as there is now nothing in the $_POST array - this is why you redirect, so a user won't resubmit the form on refresh. What you should do is create your own validation rule in a callback function in the same controller. See here codeigniter.com/user_guide/libraries/for... What you need to do is pass the email to a model in the callback that will check the email against your database and return false if it is already there.

This way, your form will not be valid and not redirect if the email already exists.

Yeah. That's what I ended up doing eventually. – Damchey Jun 4 at 18:50.

I was just adding a form to an old CI installation minutes ago and had this issue. It's funny you should mention it. Since set_value() and the related functions are only reading the $_POST data, they will not hold the value after a refresh.

You have a few options: Don't redirect until the form is valid. Assign the $_POST array to a flashdata (session) variable, and copy it to the $_POST array manually after the redirect Write your own group of functions to handle this with either flashdata or session data or other method, and don't use the set_value() functions. For the quickest fix, use #1.

I don't like manually setting $_POST values, so I don't really endorse #2, but it should work. For the long term - use #3. I find that the CI form handling is often lacking, and my personal form interaction code base has grown quite a bit over time.

Then after the database check, I may need to store the errors in a variable and display it. By the way, after posting the question, I read something about callback functions in form_validation. Eg: $this->form_validation->set_rules('email','Email Address', 'required|valid_email|callback_username_check'); Did you ever use it?

If so, is it a good idea to do it that way? – Damchey Jun 4 at 12:34 @DamcheyLhendup: If you are already assigning the errors to flashdata, it won't be affected (but it does not do this for you automatically). A callback function would indeed be appropriate for checking if the user exists - I would recommend it.

It's hard to give you specific advice without seeing how you have this set up, but in general solution #1 is what would I do. – Madmartigan Jun 4 at 12:43.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions