Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm using Symfony for a while and I think that Symfony's solution is optimal. The way it works is that you have routings (I think that CI has routings too: <a href="http://codeigniter.com/user_guide/general/routing.html" rel="nofollow">CI routings</a>) and in your controller you can do something like this in your "create" method:</p> <pre><code>if the form is valid set flash notice message redirect to (your homepage or something else defined in your routing file) else set flash error message set the current view to form </code></pre> <p>Your form's action is the same controller with the "create" action (which can be only reached via a POST request). The form which you can reach with GET requests is the "new" method. So if you click submit on your form you go to the create method, but the new method generates your form for the first time. If your form does not validate you stay there with flash error messages. If you click back you get a new form, but if the form validates your action (method) redirects to a custom page you set before in the if statement above.</p> <p>This method works with ajax too, you can check in your action if the request is an XHTTP one, you just return if the form validates or not and you can handle things in javascript. I think that this is the best way to handle forms and if your user does not have javascript enabled he can still use the "standard" way. And by the way: "create" and "new" uses the same template (view). I hope that i made things clear.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload