Gossamer Forum
Home : Products : DBMan : Installation :

If statement in html_record

Quote Reply
If statement in html_record
I would like to have an if/else statement to print the word "Email" when displaying records that contain a valid email address, but I can't get code below to work.

Any suggestions?


sub html_record {
# --------------------------------------------------------
# How a record will be displayed. This is used primarily in
# returning search results and how it is formatted. The record to
# be displayed will be in the %rec hash.

my (%rec) = @_; # Load any defaults to put in the VALUE field.
($db_auto_generate and print &build_html_record(%rec) and return);

my $font_color = 'Font face="Verdana, Arial, Helvetica" Size=2 Color=#003399';
my $font = 'Font face="Verdana, Arial, Helvetica" Size=2';

print qq|
<font face="arial" color="white">


<br><b>$rec{'Name'}, </b>$rec{'Title'}<br>
$rec{'Company'}<br>
$rec{'Address'}<br>
$rec{'City'}, $rec{'State'} $rec{'Zip'}<br>|;


if ( $rec{'Email'} eq '.+@.+\..+' )
{
print qq~ Email: $rec{'Email'}<br> ~;
}
else
{ print qq| <br>|;
}
;

Quote Reply
Re: If statement in html_record In reply to
Here's your problem:

if ( $rec{'Email'} eq '.+@.+\..+' )

It should be

if ( $rec{'Email'} =~ '.+@.+\..+' )

------------------
JPD
Quote Reply
Re: If statement in html_record In reply to
Thanks that worked great, but there's something strange, I added two more fields, put the below code below in.

It works the way I have it fine for both the Office field and Fax field but not for the Email field.

Would that be because of @ in the email address?

Just wondering.

Thanks much for your help.


<br><b>$rec{'Name'}, </b>$rec{'Title'}<br>
$rec{'Company'}<br>
$rec{'Address'}<br>
$rec{'City'}, $rec{'State'} $rec{'Zip'}<br>|;

print " Office\: $rec{'Office'}<br>" if ($rec{'Office'}) ;
print " Fax\: $rec{'Fax'}<br>" if ($rec{'Fax'}) ;
#print " Email: $rec{'Email'}<br>" if ($rec{'Email'}) ;

# if ( $rec{'Email'} eq "'.+@.+\..+'" )
if ( $rec{'Email'} =~ '.+@.+\..+' )
{
print qq~ Email: $rec{'Email'}<br> ~;
}
else
{ print qq| |;
}
;
Quote Reply
Re: If statement in html_record In reply to
Well, sorta. I only looked at one thing and should have looked at the whole thing! Smile

It should be

if ( $rec{'Email'} =~ /.+\@.+\..+/ )

This time I tested it! Smile

------------------
JPD