Results 1 to 5 of 5

Thread: Form Help

  1. #1
    Join Date
    Feb 2006
    Location
    Ontario Canada
    Posts
    4,587
    Tokens
    0

    Latest Awards:

    Default Form Help

    Ok why is this not replacing the input text (from a form) with smileys and filtering the bad words.

    PHP Code:
    <?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($readfilesize('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

    ?>

    .:.:#14:.:. .:.: Impossible Is Nothing :.:. .:.: 845 Rep:.:.
    .:.: Stand up for what is right, even if you stand alone:.:.


  2. #2
    Join Date
    Aug 2008
    Location
    Australia!
    Posts
    33
    Tokens
    0

    Default

    Code:
    <?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.


  3. #3
    Join Date
    Feb 2006
    Location
    Ontario Canada
    Posts
    4,587
    Tokens
    0

    Latest Awards:

    Default

    it wasn't made by me, it's throw together bits of scripts.

    .:.:#14:.:. .:.: Impossible Is Nothing :.:. .:.: 845 Rep:.:.
    .:.: Stand up for what is right, even if you stand alone:.:.


  4. #4
    Join Date
    Feb 2009
    Posts
    131
    Tokens
    0

    Default

    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('', '<img src="http://www.colin-roberts.net/news/data/emoticons/laughing.gif" alt="" />', $message);
    $message = str_replace('', '<img src="ttp://www.colin-roberts.net/news/data/emoticons/wink.gif" alt="" />', $message);

  5. #5
    Join Date
    Feb 2006
    Location
    Ontario Canada
    Posts
    4,587
    Tokens
    0

    Latest Awards:

    Default

    it's not like that on the actual script. it just copied weird.

    .:.:#14:.:. .:.: Impossible Is Nothing :.:. .:.: 845 Rep:.:.
    .:.: Stand up for what is right, even if you stand alone:.:.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •