We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Module MCP method only working with get, not post

Development and Programming

M Turner's avatar
M Turner
1 posts
14 years ago
M Turner's avatar M Turner

Okay, so this is the first time i’ve written a module so probably a newb question here!

I’m slowly building up a module and one of the things it needs to be able to do is save settings.

So in my mcp file i have an ‘index’ method and a ‘save_settings’ method.

function save_settings()
    {
        error_log('save settings function');
        $this->EE->session->set_flashdata('message_success', $this->EE->lang->line('record_added'));
        $this->EE->functions->redirect(BASE.AMP.'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module=refer_a_friend');
    }

Right now, the save settings method doesn’t really do anything, it just flashes a success message and redirects to the module index page.

The thing is, it only words when I access it directly by typing in the method name in the browser address bar.

When I submit the form on the index page which calls it, I wind up at the control panel home page. When I take the form action attribute and paste it directly into the address bar, I get the desired action, so I know it’s not a problem with my form action attribute.

I have an error log in there, and I can see that it isn’t being processed at all when I submit my form.

I have looked at the apache log but no clue there… this is what happens:

127.0.0.1 - - [09/Sep/2011:15:34:25 -0700] "POST /system/index.php?S=fa1a9ef3d8437ec0d33da8e0012b2d37467291bb&D=cp&C=addons_modules&M=show_module_cp&module=refer_a_friend&method=save_settings HTTP/1.1" 302 20
127.0.0.1 - - [09/Sep/2011:15:34:25 -0700] "GET /system/index.php?S=fa1a9ef3d8437ec0d33da8e0012b2d37467291bb&D=cp HTTP/1.1" 302 20

But if I enter the URL (get) it goes where I expect it to

127.0.0.1 - - [09/Sep/2011:15:34:49 -0700] "GET /system/index.php?S=fa1a9ef3d8437ec0d33da8e0012b2d37467291bb&D=cp&C=addons_modules&M=show_module_cp&module=refer_a_friend&method=save_settings HTTP/1.1" 302 20
127.0.0.1 - - [09/Sep/2011:15:34:50 -0700] "GET /system/index.php?S=fa1a9ef3d8437ec0d33da8e0012b2d37467291bb&D=cp&C=addons_modules&M=show_module_cp&module=refer_a_friend HTTP/1.1" 200 13664

I’ve spent a couple of hours trying things here, including looking at other 3rd party modules, so any pointers greatly appreciated.

       
Laisvunas's avatar
Laisvunas
879 posts
14 years ago
Laisvunas's avatar Laisvunas

Hi,

I just encountered this issue too.

It seems that something is missing in the code which is being outputted by Package Builder for ExpressionEngine.

It seems that it is possible to avoid unneeded redirect to CP homepage by adopting approach used in Bitly module.

Still, it would be interesting to find what causes that redirect.

I will return to coding and investigation of this issue Monday.

If you will find some clue, please, post your findings here.

       
Laisvunas's avatar
Laisvunas
879 posts
14 years ago
Laisvunas's avatar Laisvunas

Hi again,

I did not find what causes unneeded redirect, but compiled a minimal module, which does nothing, but avoids that redirect after submission of settings form.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.