adding php to articles

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
murdocha
Posts: 4
Joined: Sun May 13, 2007 2:19 pm

adding php to articles

Post by murdocha »

So I'm trying to add some php code to one of my articles so that people can sign up for a news letter. The problem is that serendipity tries to alter the code.

Does anyone know how to work around this problem?

I'm trying to add the follwoing:

<?php
print "<form action='$yourfilepath/sub.php' target ='_blank' method='post'>";
print "<center>E-mail: <input type='text' name='email' size='30'></center><br>";
?>
<?php
print "<center><input type='radio' name='choice' value='sub' checked> Subscribe    ";
print "<input type='radio' name='choice' value='unsub'> Unsubscribe</center><br>";
?>

<?php
print "<center><input type='submit' name='submit' value='Subscribe Now!'></center></form>";
?>
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: adding php to articles

Post by garvinhicking »

Hi!

PHP is not allowed within entries, please read here:

http://www.s9y.org/78.html#A5

Does anyone know how to work around this problem?
Serendipity is centered around plugins, so you should write a plugin that does what you need. It is much cleaner, and mcuh more secure. By having your code in an entry, whenever you modify the code you would need to edit each single entry in which you used it. By having a plugin, you only have one occurence of this to alter.

So I advise to get familiar with the plugin API and the Smarty templating. Once you get the hang of it, it is really easy to do. Best look at existing plugins that are somewhat related to what you need to do. Like the 'Send email to friends' plugin or the social bookmarks plugin, they both emit custom HTML/Smarty markup after an entry.

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/
Don Chambers
Regular
Posts: 3659
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Post by Don Chambers »

If you can live with just an email to yourself, triggered by users completing a form, check out the contact form plugin. It is surprisingly flexible and can be used for much more than a simple contact form. I use it as an event registration form.
=Don=
Post Reply