PHP in an HTML Nugget

Creating and modifying plugins.
Post Reply
terrym
Regular
Posts: 23
Joined: Mon Jul 23, 2012 10:28 am
Location: Blackburn, UK
Contact:

PHP in an HTML Nugget

Post by terrym »

Hi all

I have inserted an HTML Nugget into a sidebar and then placed a bit of HTML code into it. Naturally, this worked exactly as expected.

So I then inserted a second HTML Nugget directly below the first one. If I then put a bit of HTML code into this nugget, it also works as expected. But what I am really trying to do is to put some HTML code together with a bit of PHP code into this nugget. But it doesn't seem to want to parse the PHP bit and just displays it along with the HTML result. Just in case I'm completely on the wrong track, below is why I want to do this. Maybe there is another better way?

I want to place a small form in the sidebar. When the visitor fills in the form and clicks the Submit button, any entered comments in the form are emailed to me. I tried MAILTO: but that was too messy! I have found that my host has Pear Mail installed, so I then put a form in the nugget which loaded an external PHP file to send the email to me with the form data.

Now, this all worked except if I wanted to display a message telling the visitor that the email was sent, then this message was displayed on a new blank page. Which also isn't very nice!

So then I tried to put the PHP code in the "same page" as the HTML code, which obviously works outside Serendipity, but not in a HTML Nugget.

Does anyone know of a plugin or another method that will enable my to achieve what I'm trying to do?

Thanks
Terry
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: PHP in an HTML Nugget

Post by garvinhicking »

Hi!

PHP is not HTML; thus PHP will not be parsed when you use HTML output. Just like PHP would not be executed when you copy&paste it here to the forums.

The solution is to use the "Include External script" sidebar plugin that allows you to include an existing PHP file (where you can also put your HTML into). Also you can search this forum for "PHP nugget", whoever this is not recommended due to the security issues this implies.

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
terrym
Regular
Posts: 23
Joined: Mon Jul 23, 2012 10:28 am
Location: Blackburn, UK
Contact:

Re: PHP in an HTML Nugget

Post by terrym »

Hi Garvin

I do actually know what PHP and HTML are, but that's not the point of this inquiry. I have now installed the "serendipity_plugin_externalphp" plugin, and I can see it in the sidebar.

Could you please tell me how it is to be used? Can I paste into it the php code itself? Or maybe just put some sort of link to and external php file? Or a php include() perhaps?

Or maybe there is some document which explains all of this?

Terry
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: PHP in an HTML Nugget

Post by garvinhicking »

Hi!

OK, now you create the PHP file with all the PHP code you want, save that i.e. in your serendipity directory (i.e. /serendipity/php/myfile.php).

Then you setup the sidebar plugin and enter /home/www/serendipity/php/myfile.php as the file to include. Mind your actual directory names, of course.

s9y will then simply include() exactly that file you configured.

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply