PDA

View Full Version : inserting html link in php function


marnimatul
May 5th, 2006, 22:41
if (empty($name) || empty($email) || empty($subject) || empty($msg))
{
echo " <center><p><h3>Sorry, you missed some required fields. Please go back and re-enter your information.</h3></p></center>";
}
elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
print " <center><p><h3>Sorry the email address you entered looks like it's invalid.</h3></p></center>";
}
else
{
mail($to, $sub, $mes, $headers);
print " <center><p><h1><center>Thank you, ".$name.", for registering for JBN Media Access.<br>
</center></h1></p></center><br>";

}
?>

I don't really know what I am doing. I got this php code for forms and changed it for myself. My problem is that when the form validates I want to offer a link to another page only in the final 'else' statement in the code above. I just can't seem to do it right. I can put it after the php close tag but then the link shows up even when the form doesn't validate. Please help!

the_pm
May 5th, 2006, 22:56
First of all, be very careful to ensure your script does not allow spammers to use your site as a spam portal. Someone with more experience in PHP than me will be able to help you more with putting together a filtering function that will stonewall spammers.

Next, I'm guessing the problem you're having has to do with using quotes inside your <a href>. The way to write quotes so that PHP doesn't attempt to interact with them is to place a backslash in front of them (this is called 'escaping' them). Try this and see if it works:
print " <center><p><h1><center>Thank you, ".$name.", for registering for JBN Media Access.<br><a href=\"some_other_web_page.html\">Go to some other Web page</a></center></h1></p></center><br>";

marnimatul
May 5th, 2006, 23:05
I was doing all kinds of other stuff and making it more difficult than it really was. *doh*

And I do need help making sure spammers don't take advantage of my email forms like Paul said. Please help if you can.

THANK YOU!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Gerrit
May 12th, 2006, 13:45
Here's an article that will help you: Protect PHP mailforms (http://www.phpbuilder.com/columns/ian_gilfillan20060412.php3)

Good luck!