Form validation and redirects |
[eluser]ToddyBoy[/eluser]
I have a problem with form validation and how to take the user to where I want them to go with appropriate messages included. I've used something like this Code: function send_request() The thing I would like to know is if I can change the loading of a view to a redirect (to the same page) if the validation fails. Here is what I mean. Say my original URL is www.mysite.com/page/another-page. This location has a form in it which submits to /page/send_request. If the form validation fails, the load view shows the original page under the URL of /page/send_request. I don't want the user to see that /page/send_request location. I would like to try something like Code: function send_request() I realise that a redirect clears form post data. Is there a way to somehow keep the form data and still use a redirect? I'm thinking that a session might be the answer but I would rather avoid creating and destroying sessions.
[eluser]pickupman[/eluser]
You are correct, setting session variables would be the only way to carry to another URL. As a thought, how many users actually look a url? When you have filled out a form, have you ever paid attention to the url?
[eluser]smilie[/eluser]
I know what you mean. There is a way around it, but it requires a lot more of code to be written and as pickupman said - if you do not care about URL too much I wouldn't bother. Anyway, this is the way, so if you like it - use it Code: function form($action='') This way, you always stay on a same controller - ergo you always have same URL. However, you will have to expand your 'form' view php file to accept $message and also to send extra hidden form 'submitted'. This way in your controller you can decide if form has been submitted - or do you need to display 'empty' form. Hope this helps. Regards, Smilie |
Welcome Guest, Not a member yet? Register Sign In |