I am currently building an extension, wondering if it possible to have two forms with two independent save methods. I realize that I could use the save_settings() method for both forms but that solution is a little kludgy.
Example:
<?=form_open('C=addons_extensions'.AMP.'M=save_extension_settings'.AMP.'file=my_extension');?>Works fine, calls default save method
<?=form_open('C=addons_extensions'.AMP.'M=save_extension_settings'.AMP.'file=my_extension'.AMP.'method=save_second_form_settings');?>Does not work as intended, calls the same method as the previous form action.
It is possible to do this in an extension?
You could use the same base url (your first one) and add an additional GET parameter. Your save_settings() method could just be a router and look something like this:
function save_settings()
{
return ($this->EE->input->get('method') == 'save_second_form_settings') ? $this->process_two() : $this->process_one() ;
}Do you see what I’m getting at?
Thanks, that’s exactly what I ended up doing.
Was wondering if there was cleaner/EE 2.0 way doing it as it feels a little dirty to me.
Is this just how extensions work? Had I made my plugin a module instead would I be able to map save form actions to any method in my controller?
Is this just how extensions work? Had I made my plugin a module instead would I be able to map save form actions to any method in my controller?
Yes, Extensions are designed to have a single settings screen. You are correct in that a module would give you the ability to create as many forms as needed within the Control Panel. By using the mcp.{module_name}.php file you can build all of that.
You may still need the extension if you’re using a hook though. So you’ll end up with an add-on package containing both an Extension and a Module.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.