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

EE, Forms, PHP, Includes, Embeds, and madness

Development and Programming

Adam George's avatar
Adam George
283 posts
18 years ago
Adam George's avatar Adam George

I have a rather complex form which I need to reproduce in EE.

The form relies on PHP for validation, submission, and email sending.

Formerly, I just used a few php includes and away I went, but trying to get it to work in EE is making me go insane.

I’ve tried php includes - don’t seem to work?

I’ve tried putting the php into templates and using the embed tag. The problem seems to be that the embed tag is parsed last, or close to last, so even though I have the php embeded using the embed tag up the top of my template, using any php lower down the page fails because it is dependant on what’s in the embedded template.

I can’t solely use embeds because the php is scattered throughout the page in little bits and pieces, for example, only showing a certain form field if a condition is met.

I have turned on php for all the templates at input stage.

EE Version: 1.6.0 Build: 20070724

Help!

Thanks - Adam

Moved to Plugins forum by Moderator

       
silenz's avatar
silenz
1,648 posts
18 years ago
silenz's avatar silenz

As far as PHP include() is concerned, that does work. Have you enabled “PHP/SQL error messages” in Output and Debugging Preferences? Does it throw any errors when you’re including stuff?

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

You are correct, Adam, embeds are not parsed until the parent template has been fully parsed, including any PHP. Chances are, you would be best creating a plugin with your PHP instead of directly in the template. 9 times out of 10 if you have more than a few lines of PHP, a plugin is actually simpler.

       
Adam George's avatar
Adam George
283 posts
18 years ago
Adam George's avatar Adam George

Thanks guys. Derek, if I make a plugin, and my page looks like this:

Do some php here…. ………………… <html> <body> ….. <? scattering of php dependant on functions defined above ?> ………………… ………. <? scattering of php dependant on functions defined above ?> …………………… </body> </html>

Do I need to put all the php into the plugin (i.e. pretty much the whole page), or just the php that defines everything?

Thanks!

       
Robin Sowell's avatar
Robin Sowell
13,160 posts
18 years ago
Robin Sowell's avatar Robin Sowell

Derek may chime in with a more complete answer- but to me, it’s hard to say without knowing the code and exactly what you’re doing with it. I could shift this over to ‘How to’ or probably ‘Plugins’ if you want to go into detail on it?

       
Adam George's avatar
Adam George
283 posts
18 years ago
Adam George's avatar Adam George

Yes please 😊

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

I would put all PHP that is related to the same behavior in a plugin. You can use multiple plugin tags/methods depending on what you need, and can store values from the “top down” so the plugin has access to the same information. That is to say, your first PHP tag can load up whatever information you need, and store it in $SESS->cache, and the other plugin tags on the page can then access that information without having to set it all up again. See the Developer Guidelines (previous link) for details.

       
Adam George's avatar
Adam George
283 posts
18 years ago
Adam George's avatar Adam George

Thanks for the advice Derek.

       

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.