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 Tutorial help

Development and Programming

kmertig's avatar
kmertig
24 posts
17 years ago
kmertig's avatar kmertig

I am new to EE and EE module building.

I have read the module tutorial (http://expressionengine.com/docs/development/index.html), but I still have many questions.

The most important thing would be for the zip file (Zip Archive of Module Tutorial Example) to actually exist or not be corrupted or whatever the case may be. I have asked several colleagues to try and download this file, and they receive the same error. I tried copying the code from the web pages, and uploading that, but I got an error on my modules page, so I had to pull it off the FTP server.

Also, what would be really be helpful would be a relatively simple module example with explanation. The explanations provided for the fortunes module tutorial are not always clear, in particular when and why you need to add rows to the exp_actions table.

From the tutorial (http://expressionengine.com/docs/development/tutorial.html):

Occasionally, a module will require that certain actions be performed on the use side of the site. An example of this is when a form is being submitted and the module needs to gather and process the data. When this is required, the module needs to enter the class and method that the system needs to call to perform into the exp_actions database table during the installation of the module. Here is an example from the mcp.comments.php file.

I have have highlighted 2 parts from the tutorial provided as examples.

use side of the site - huh?

mcp.comments.php - this file is not even part of the example (mcp.fortunes.php). Fortunes does appear however to insert rows into the exp_actions table based on further code provided on the page because its deinstall function deletes them, however it is not explained why.

And just for clarification - does a row have to be inserted into exp_actions for any function that inserts, updates, or deletes data in the database?

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Hi kmertig, welcome to the community and thanks for the feedback. That particular document was written quite some time ago, and alas, is showing its age. Our small team and current development schedule has not allowed us to revisit that tutorial and give it a better treatment. If you are an experienced PHP developer, it may be faster for you to look at one of the modules supplied with ExpressionEngine that has its own control panel (like the Wiki or Simple Commerce) to see how it all comes together. That said, to the point of your questions:

use side of the site - huh?

Typo, whoops. That should be “user” side of the site, i.e your front-end pages.

mcp.comments.php - this file is not even part of the example (mcp.fortunes.php). Fortunes does appear however to insert rows into the exp_actions table based on further code provided on the page because its deinstall function deletes them, however it is not explained why.

The example from the Comments module (part of ExpressionEngine) is given as it’s a more well understood general action. Someone submits a comment, the form data needs to be processed, and so on.

The exp_actions DELETE query for the Fortunes module is given so that you can see the standard set of queries that a module deinstaller will typically need to clean up after itself.

And just for clarification - does a row have to be inserted into exp_actions for any function that inserts, updates, or deletes data in the database?

Nope, not at all. “Actions” are generally used when forms are involved - or at least when something needs to be triggered by an action or input triggered by the user. Why? Requests in ExpressionEngine are URL based, relying on the template group and template to know where to go, so to speak. Instead of requiring a certain tag to exist on a template to handle form data, Action urls are. This way nothing is required on the template to trigger code that handles the request - your class and method that you supply to the exp_action table automatically handles it. Make sense?

       
kmertig's avatar
kmertig
24 posts
17 years ago
kmertig's avatar kmertig

Derek, thanks for your reply!

So, in other words, it is not necessary to insert rows into exp_actions in order for your module to word? I am not saying that I wouldn’t, but I just want to make sure the my module won’t break if I am not using it “correctly”.

And, yes your explanation for the exp_actions inserts does make sense. Thanks!

Kelley

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Right, many modules will never use the exp_actions table.

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
17 years ago
Leevi Graham's avatar Leevi Graham

Hey Derek,

Can you please explain when the actions are run and what triggers them. Specifically I am trying to capture a form submission.

So far I have

"INSERT INTO exp_actions (action_id, class, method) VALUES ('', 'Lg_new_module', 'handle_form')"

and then in the Lg_new_module class I have:

function handle_form(){print("yay"); exit;}

My form just submits back to itself but the method is not fired.

Is there a basic tutorial on hadling form submissions. I have been through the comment module code and nothing seems to be different in my basic setup.

Cheers

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
17 years ago
Leevi Graham's avatar Leevi Graham

Ok I just checked out the freeform module and it has a hidden field

<input type="hidden" value="20" name="ACT"/>

I’m guessing this calls the action and the action id is 20.

What is the best practice to generate a form with these hidden values from the mod. file?

Cheers

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
17 years ago
Leevi Graham's avatar Leevi Graham

One step closer…

I am now building my form using the following code:

$form_data['hidden_fields'] = array(
                     'ACT'    => $FNS->fetch_action_id('Lg_module', 'insert_new_entry'),
                     'URI'    => ($IN->URI == '') ? 'index' : $IN->URI,
                     'XID'    => ( ! isset($_POST['XID'])) ? '' : $_POST['XID']
              );
        $form_data['action']    = $FNS->create_url( $IN->URI );
        $form_data['enctype']   = '';
        
        $template = $FNS->form_declaration($form_data);
        
        // form fields removed

        $template = $TMPL->swap_var_single("button", "<input type='submit' value='Submit'>", $template);
        $template .= "</form>";
        
        return str_replace('/', '/', $template);[/code]

which is all good.. It renders the form with some hidden inputs

[code]<form action="/index.php/" method="post">
<div class="hiddenFields">
<input type="hidden" value="20" name="ACT"/>
<input type="hidden" value="index" name="URI"/>
<input type="hidden" value="7da75365e421b2951fde248485834499236c4a81" name="XID"/>
<input type="hidden" value="1" name="site_id"/>
</div>

<input class="button" type="submit" value="Submit"/>
</form>

However when I submit the form I get the following error:

The action you have requested is invalid.

Anyone got any ideas?

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
17 years ago
Leevi Graham's avatar Leevi Graham
"INSERT INTO exp_actions (action_id, class, method) VALUES ('', 'Lg_new_module', 'handle_form')"

OK figured it out… The class value must be same as the module folder. Mine was plural and I was using a singular version.

Just incase someone else runs into this issue.

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

::wakes up and sips some coffee::

Glad I could help, Leevi! 😉

       

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.