Everyone on this list would write this stuff everyday.  The catch is that my
needs change for almost every application, so I haven't written a class as
yet.

However, generally, what you want to achieve can be done easily.

I'd recommend you write down a list of EVERYTHING you'd like to achieve, and
then we can help you build some code to use, or recommend a class.


To wet your appetite, have a look at the string functions in the manual, and
check out this code:


<?

$string = "blah blah <HR> blah<BR> blah <u>blah</u> <script>foo</script>";
$string = strip_tags($string, "<br><p><u><i><b>);
echo $string;

// will return
// blah blah  blah<BR> blah <u>blah</u> foo

?>

or in context, it might look like this:

<?

$error = "";
$allowed_tags = "<br><p><u><i><b>";

if($textarea1 == "")
    {
    // they didn't type anything
    $error .= "you did not enter text in area 1<BR>";
    }
else
    {
    // strip out unwanted tags
    $textarea1 = strip_tags($allowed_tags, $textarea1);
    //
    // do other stuff
    //
    }

if($error == "")
    {
    // insert into DB
    }
else
    {
    // show form again with $error message
    }

?>


Again, it depends what you want to do.  You might want to:

a) validate if they entered anything at all (easy)
b) validate if the entry is more or less than a certain length
c) validate if the entry is all numbers (eg for "age") or all alpha (a-z)
d) trim long input down to a smaller size
e) strip all, or a limited subset, of tags out of the entry
f) strip javascript out of the entry
g) make sure the input matches a certain string, or doesn't contain a string
h) convert any newlines in the text into <br>'s


So, first you need to think about what you want to do, then you can either
look for, or build the right class or function or code to suit your needs.


Justin French
---------------------
http://indent.com.au
http://soundpimps.com
---------------------


on 26/04/02 4:59 AM, Tarjei Huse ([EMAIL PROTECTED]) wrote:

> Hi,
> 
> I need a function or class to validate a form with a cuple of text areas
> that are alloed to contain a few html tags (<br><p> etc) but not all,
> and I need a script to validate the input from the fields and stop the
> html elements that are not allowed.
> 
> Does anyone have a function or class handy that I might use? (for free)
> 
> Thanks
> Tarjei


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to