Welcome Guest, Not a member yet? Register   Sign In
Display a set_message for each bad wor found in string
#1

When the user types in a couple of word lets say ban and bad in string.

How could I get my set_message() to out put error message for each word found.

Currently only displays one message.


PHP Code:
<?php

class MY_Form_validation extends CI_Form_validation {

    public function 
badword($string) {
        
// Dummy words
        
$badWords = array("ban","bad","user","pass","stack","name","html");
        
$matches = array();
        
$matchFound preg_match_all("/\b(" implode($badWords,"|") . ")\b/i"$string$matches);

        if (
$matchFound) {
         
     
              $words 
array_unique($matches[0]);
         
     
              
foreach($words as $word) {
         
         $this->set_message('badword''Your message has a band word <b>' $word '</b> you can not use that word.');
         
     }

         
     return false;
        
        } else {

            return 
true;
        }

    }

There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply


Messages In This Thread
Display a set_message for each bad wor found in string - by wolfgang1983 - 09-30-2016, 01:07 AM



Theme © iAndrew 2016 - Forum software by © MyBB