Welcome Guest, Not a member yet? Register   Sign In
Similar functionality independent of the controller
#1

[eluser]bunal[/eluser]
Hi Coders,

Lets say i have an "Email Subsribtion Form" as a view. And i am including this form view into some pages/controllers through out the site. The subscription form has action = "" cause i want it to post to the current url.

Before using CI i used to have a function.php file and i was checking the POST['action'] to do somekind of bootscraping for my actions like below. So i could use the form anywhere i want.

Code:
switch($_POST['action']){

case "addtonewsletter":

break;


case "removefromnewsletter":

break;


}

Currently i have started to use CI. For the newsletter form i can have action as "/newsletter/register" and then can have Controller => newsletter with Method => Register. But this is not the thing i want.

How can achieve similar functionality as my old function.php so i can use the subscription anywhere?

I guess i can have MY_Controller.php and then? Whats your thoughts?
#2

[eluser]n0xie[/eluser]
Quote:The subscription form has action = “” cause i want it to post to the current url.
Why?

This would be a non issue if you would just POST it to 1 controller which takes care of newsletter related methods.
#3

[eluser]BrianDHall[/eluser]
I do this with login, so you can login by posting to any controller. I use the constructor of the controller or MY_Controller. Then it just works.
#4

[eluser]bunal[/eluser]
Thanks for the replies.

I'll go having the stuff in the constructor of the controller or MY_Controller

@n0xie: Sometimes it is needed be on the same page for example for error showing. Lets say you are on "index page" there is a sidebar and in the sidebar there is newsletter subs. form. When you post to newsletter controller, you need to redirect user back to "index page" with some Get params in the url stating the error and use these params to show/parse errors on the page. But if you post to same page since there is no redirection i can have the errors in a variable and view can directly use these variables to show errors. Hope i could explain it.
#5

[eluser]n0xie[/eluser]
I understand what you are saying, but I wouldn't call that an issue. First off this could easily be solved using Ajax, which gives you a cleaner solution anyway (mind you, I'm NOT a big ajax fan, but for this sort thing it's very handy). Second, most sites redirect you to an 'error page' when an error occurs, because the error message usually breaks the basic layout.

Take for example this forum or Twitter. Both give you a top bar where you can login from any page, yet if you fail to login, you are redirected to an error page.

I'm not saying there is anything particularly wrong with the MY_Controller approach, just pointing out that there are other ways to solve this.




Theme © iAndrew 2016 - Forum software by © MyBB