开发者

Good practices for handling form submission on codeigniter/php website

I'm building a website with codeigniter and I'm creating a form for user submission.

I'm thinking about having the form submit with an javasc开发者_开发技巧ript/AJAX call to a special controller intended just to handle form submissions and redirecting the user to an appropriate page based off the response from that controller.

Is this a good idea? I imagine my site will have lots of forms so I'm thinking a special controller just to handle their submission is a good idea. But obviously I will need to prevent users from ever directly accessing any of the methods in this controller.


Make sure your form works without javascript, and then you can use $this->input->is_ajax_request() to check if the form is being submitted with ajax, and do something different with your output.

This avoids the need for "ajax only" controllers, methods, and URLs, and keeps all your form processing logic together in one place. If it's not an ajax request, no one will ever be able to see the output so you don't need to worry.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜