Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

turning images on and off 2

Status
Not open for further replies.

MAWarGod

Programmer
Feb 15, 2002
352
US
Code:
sub HtmlFilter
{
local($filter) = @_;
# 
# The following filters the HTML images
# out, if they are disallowed.  The code
# after this, filters out all HTML if it
# is disallowed.
#
if ($no_html_images eq "off")
{
    $filter =~ s/<(IMG\s*SRC.*)>/&LT;$1&GT;/ig;
} # End of parsing out no images

if ($no_html eq "on")
{
    $filter =~ s/<([^>]+)>/\&LT;$1&GT;/ig;
} # End of No html                                         

$filter;

Is there a way to toggle the $no_html_images on and off?

Code:
</TR>
<TR>
<TD ALIGHT=RIGHT>Pic on or off:</TD>
 <TD><select size=1 name=no_html_images>
  <option selected value=ON>ON</option>
  <option value=OFF>OFF</option>
  </select></TD>

I tryed it this way no luck

MA WarGod

I believe if someone can think it, it can be programmed
 
you send upper-case "ON":

<option selected value=ON>ON</option>

but you check for lower-case "on"

if ($no_html eq "on")

change the above line to:

if ($no_html eq 'ON')





- Kevin, perl coder unexceptional!
 
Oh I get it now Thak You Kevin..
and I am still working with the format You gave for begaining.
so thank You again
 
no still not working

Code:
sub HtmlFilter
{
local($filter) = @_;
# 
# The following filters the HTML images
# out, if they are disallowed.  The code
# after this, filters out all HTML if it
# is disallowed.
#
if ($no_html_images eq "off")
{
    $filter =~ s/<(IMG\s*SRC.*)>/&LT;$1&GT;/ig;
} # End of parsing out no images

if ($no_html eq "on")
{
    $filter =~ s/<([^>]+)>/\&LT;$1&GT;/ig;
} # End of No html                                         

$filter;

} # End of HTML Filter

Code:
<TD ALIGHT=RIGHT>Pic on or off:</TD>
 <TD><select size=1 name=no_html_images>
  <option selected value=on>ON</option>
  <option value=off>OFF</option>
  </select></TD>

or should I from the sub different
like
if ($no_html_images eq "$_")
{
$filter =~ s/<(IMG\s*SRC.*)>/&LT;$1&GT;/ig;
} # End of parsing out no images

if ($no_html eq "off")
{
$filter =~ s/<([^>]+)>/\&LT;$1&GT;/ig;
} # End of No html

$filter;


????????
 
can you see a problem here?

Code:
if ([b]$no_html_images[/b] eq "off")
{
    $filter =~ s/<(IMG\s*SRC.*)>/&LT;$1&GT;/ig;
} # End of parsing out no images

if ([b]$no_html[/b] eq "on")

or is it supposed to be like that?

- Kevin, perl coder unexceptional!
 
I think you'll save yourself a lot of brain ache down the road if you eliminate the double negative: does "no_html_images=off" mean you get images or you don't?

Furthermore, testing for "off" and "on" is asking for trouble once you start passing values of "Off", or "ON", or " off", or whatever else. Get used to thinking like a computer and use 1 for yes, 0 for no. Actually, it's quite common in CGI programming to treat any non-zero, non-null value as "yes" and 0 or "" as "no" - so your form could be like this:
Code:
<input type="checkbox" checked="checked" value="1" name="images_allowed">
And your perl would be like this
Code:
unless ($images_allowed)
{
    $filter =~ s/<(IMG\s*SRC.*)>/&LT;$1&GT;/ig;
} # End of parsing out no images
(assuming you've done the necessary work to get the form parameter into $images_allowed first)


-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top