Page 1 of 1

adding php to articles

Posted: Sun Jun 17, 2007 11:15 pm
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>";
?>

Re: adding php to articles

Posted: Mon Jun 18, 2007 2:25 pm
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

Posted: Wed Jun 20, 2007 4:11 am
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.