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?
Thanks for the help
[Mod Edit: Moved to the Modules: Discussion & Questions forum]
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.
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
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!
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.