Log in

View Full Version : Form Help



Colin-Roberts
02-02-2009, 10:24 PM
Ok why is this not replacing the input text (from a form) with smileys and filtering the bad words.


<?php
//Get varibles
$name = $_POST['name'];
$website = $_POST['website'];
$message = $_POST['message'];
//Define functions
function filter($message)
{
//replace the veg with sware words.
$bad_words = explode(',', "*******,****,*****,*******,ass,*******,****,****,* ****" );
foreach ($bad_words as $naughty)
{
$msg = eregi_replace($naughty, "****", $message);
}
return $msg;
}
function doSmily($message)
{
$msg = str_replace(':)', '<img src="ttp://www.colin-roberts.net/news/rte/images/smiley.gif" alt=":)" />', $msg);
$msg = str_replace(':(', '<img src="ttp://www.colin-roberts.net/news/data/emoticons/sad.gif" alt=":("', $msg);
$msg = str_replace(':D', '<img src="http://www.colin-roberts.net/news/data/emoticons/laughing.gif" alt=":D" />', $msg);
$msg = str_replace(';)', '<img src="ttp://www.colin-roberts.net/news/data/emoticons/wink.gif" alt=";)" />', $msg);
$msg = str_replace('>:(', '<img src="ttp://www.colin-roberts.net/news/data/emoticons/angry.gif" alt=">:(" />', $msg);

return $message;
}

//Start the page code
if(empty($name) OR empty($message))
{

}
else
{

echo "

<script language='javascript'>

alert('Thanks for your message $name...');

</script>
";
//Before we add to the DB, we remove the bad words
$mge = filter($message);

$name = htmlspecialchars($name);
// Note, Dosmily function is called after html charicters have been removed. This is so the image codes do not also get filtered, which would stop them from showing up correctly.
$mess = doSmily(htmlspecialchars($mge));

//And the rest of your code
$tag = ("<font size=\"1\" face=\"Verdana\">
<b>$name</b>: $mess </font><br><br>");
$read = fopen("content.txt", "r");
$contents = fread($read, filesize('content.txt'));
fclose($read);

$write = fopen("content.txt", "w");
fwrite($write, "$tag $contents");
fclose($write);
}

print "<meta http-equiv=\"refresh\" content=\"0;http://www.colin-roberts.net/shoutbox/Shoutbox.htm\">";

// Copyright 2006 - 2007 Colin-Roberts.net

?>

Ryzie
03-02-2009, 07:18 AM
<?php
//Get varibles
$name = $_POST['name'];
$website = $_POST['website'];
$message = $_POST['message'];
//Define functions
function filter($message)
{
//replace the veg with sware words.
$bad_words = explode(',', "*******,****,*****,*******,ass,*******,****,****,* ****" );
foreach ($bad_words as $naughty)
{
$msg = eregi_replace($naughty, "****", $message);
}
return $msg;
}
function doSmily($message)
{
$message = str_replace(':)', '<img src="ttp://www.colin-roberts.net/news/rte/images/smiley.gif" alt=":)" />', $message);
$message = str_replace(':(', '<img src="ttp://www.colin-roberts.net/news/data/emoticons/sad.gif" alt=":(" />', $message);
$message = str_replace(':D', '<img src="http://www.colin-roberts.net/news/data/emoticons/laughing.gif" alt=":D" />', $message);
$message = str_replace(';)', '<img src="ttp://www.colin-roberts.net/news/data/emoticons/wink.gif" alt=";)" />', $message);
$message = str_replace('>:(', '<img src="ttp://www.colin-roberts.net/news/data/emoticons/angry.gif" alt=">:(" />', $message);

return $message;
}

//Start the page code
if(empty($name) OR empty($message))
{

}
else
{

echo "

<script language='javascript'>

alert('Thanks for your message $name...');

</script>
";
//Before we add to the DB, we remove the bad words
$mge = filter($message);

$name = htmlspecialchars($name);
// Note, Dosmily function is called after html charicters have been removed. This is so the image codes do not also get filtered, which would stop them from showing up correctly.
$mess = doSmily(htmlspecialchars($mge));

//And the rest of your code
$tag = ("<font size=\"1\" face=\"Verdana\">
<b>$name</b>: $mess </font><br><br>");
$read = fopen("content.txt", "r");
$contents = fread($read, filesize('content.txt'));
fclose($read);

$write = fopen("content.txt", "w");
fwrite($write, "$tag $contents");
fclose($write);
}

print "<meta http-equiv=\"refresh\" content=\"0;http://www.colin-roberts.net/shoutbox/Shoutbox.htm\">";

// Copyright 2006 - 2007 Colin-Roberts.net

?>

I someone believe that you didn't make this.

Fixed:


Closed the img tag for the sad face
replaced all $msg with $message.

Havn't tested it yet though.

Colin-Roberts
05-02-2009, 09:43 PM
it wasn't made by me, it's throw together bits of scripts.

Calgon
06-02-2009, 10:25 AM
Notice how you've incorrectly spelt "http"



$message= str_replace(':)', '<img src="ttp://www.colin-roberts.net/news/rte/images/smiley.gif" alt=":)" />', $message);
$message = str_replace(':(', '<img src="ttp://www.colin-roberts.net/news/data/emoticons/sad.gif" alt=":(" />', $message);
$message = str_replace(':D', '<img src="http://www.colin-roberts.net/news/data/emoticons/laughing.gif" alt=":D" />', $message);
$message = str_replace(';)', '<img src="ttp://www.colin-roberts.net/news/data/emoticons/wink.gif" alt=";)" />', $message);

Colin-Roberts
06-02-2009, 08:45 PM
it's not like that on the actual script. it just copied weird.

Want to hide these adverts? Register an account for free!