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
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.
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!
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.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.