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.x how do I send a response when a form is posted?

Development and Programming

TKoorn's avatar
TKoorn
64 posts
16 years ago
TKoorn's avatar TKoorn

I can now post forms so that my modules actions are called when I do so. The data is received and I can insert or update entries in the database, however I can’t send output back to the browser. The browser does receive a 200 http header but if my function returns output there is nothing going to the browser. Also how do I send an error message if the form doesn’t validate? I might want to send a different header in that case.

Moved to the Modules forum by Moderator

       
Sue Crocker's avatar
Sue Crocker
26,054 posts
16 years ago
Sue Crocker's avatar Sue Crocker

TKoorn, moving to Modules forum.

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

Hi Tkorrn

Are you using CI’s validation class? If so you can send back to the form using it’s build in validate functions. Note: You can’t use the redirect, you need to post to the same page you have your form at (ie. index.php/template_group/template/)

I have a smiliuar thread just below yours asking about what happens after an action is executed. I don’t think you can return anything so you need to make a redirect() or if theres a way to communicate to the templates instead of doing a page reload via redirect()

       
TKoorn's avatar
TKoorn
64 posts
16 years ago
TKoorn's avatar TKoorn

I just found that I can use the output class to send error messages so maybe that that class can do some other things too. I’ll check out CI’s form validator too. Thanks for the tip.

       
TKoorn's avatar
TKoorn
64 posts
16 years ago
TKoorn's avatar TKoorn

Ah it was very easy, I can just use

$this->EE->output->set_output($data);

And send stuff back to the browser.

Maybe I should use this:

$this->EE->load->view('file_name', $data, true/false);

Or maybe there is a EE way of getting a template to be outputted.

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

Can you output the templates from within the EE template-manager?

EE->output just outputs what you send it raw… or?

       
TKoorn's avatar
TKoorn
64 posts
16 years ago
TKoorn's avatar TKoorn

Yes, which is great for me because I just want to output a tiny bit of javascript.

If you want a template then I think that if you put this in your method:

$this->EE->load->helper('url');
redirect('/group/template/');

You might just get a nice and parsed template 😊 I can’t try it now, but I will in the morning.

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

Yeah the redirect is working, problem with that is your forcing a page reload which isn’t working with the form validation class if in use.

I would like to do something similuar to the load->view() but for EE’s internal templates in the template-manager. Let me know if you find anything 😊

Thanks

       

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.