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

EE2: Question about what happens after an ACT is fired

Development and Programming

esset's avatar
esset
191 posts
16 years ago
esset's avatar esset

I have a custom action called “my_action”.

If I POST to this action the engine executes it as it should.

What I wonder is what happens efter the action is executed with the platform/engine?

Right now if I don’t return anything, or do anything else, within the function “my_action” I’m drawing a blank page. Almost like the function is executed and then it’s up to the function to do something to get moving.

Additional question: 1. Can I make the engine start proccessing the template_group and template from the URL from within my function if I don’t want to return something?

  • I have a template in a template_group that has a form. This form executes “my_action” and the function runs a validation on the form. The validation fails = the template should be shown again to display errors. I can’t do a “redirect” to the template because it requires the page to reload and it seems that the validation-error-data doesn’t hold over the page reload.

Thanks for the help

[Mod Edit: Moved to the Modules: Discussion & Questions forum]

       
esset's avatar
esset
191 posts
16 years ago
esset's avatar esset

Ok wasn’t much “action” (get it? ;P) in this thread.

Let’s simple it down: Can I output a template from the template-manager from within my module?

       
Mark Croxton's avatar
Mark Croxton
319 posts
16 years ago
Mark Croxton's avatar Mark Croxton

In the module function for your action you can store any error messages generated in the session, then redirect to the form page. In the module function that displays your form, check the session for any messages and display above your form. The only issue you will encounter with this approach is how to re-popluate the form data. I currently use jquery and the ‘populate’ plugin (store the $_POST in the session and output as a json on the form page), although if you don’t want to rely on js you could do it the hard way by parsing the form html in php (actually there are existing libraries that you could use for this).

I’ve actually taken this approach a bit further and written a library file that overloads a few of the core Output class methods, so I have inline error messaging for every EE form posted.

An alternative to the above would be to use ajax for inline messages with fallback to default error messaging for those without js.

       
esset's avatar
esset
191 posts
16 years ago
esset's avatar esset

What I did was to utilize the native CI form validation class, but instead of posting to a ACT function just have the POST go to the same page and make an if-statement at the beginning of my module function that checks if the POST has happen. If it has, run the validation, and if FALSE just let the page keep processing. This way the page keeps rendering and the error messages etc shows as like if it was a load->view().

It’s a workaround but it let’s me use the awesome CI form validation.

It just doesn’t seem… right 😊 hehe. If you know what I mean.

Thanks for the input

       
Mark Croxton's avatar
Mark Croxton
319 posts
16 years ago
Mark Croxton's avatar Mark Croxton

That is in fact exactly what I do in my CI apps. As you’re not using EE’s form_declaration function, be sure to generate a hash in a hidden field and check it’s value hasn’t changed before storing your posted form data in the DB - to protect your form against CSRF.

Also, you will still need to re-popluate the form using set_value(‘field name’).

Good luck!

       

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.