Link to home
Start Free TrialLog in
Avatar of uksupafly
uksupafly

asked on

NMS Guestbook problem

I've altered the NMS guestbook.pl script slightly so it prints the guests name with a hyperlink to their email address - instead of their homepage.

The problem I have is that if they leave out their email address (or it's invalid), their name isn't printed in the guestbook.

This is the altered code:

     if ($inputs{username}){
       if ($linkmail) {
         $_ .= qq(<a href="mailto:$escaped{username}">);
         $_ .= "$escaped{realname}</a>";
       } else {
         $_ .= "$escaped{realname}";
       }
     }

     if ($inputs{'url'}) {
       $_ .= qq(<a href="$escaped{'url'}"> - Homepage</a>);
     } else {
       $_ .= " ";
     }

This is from the NMS version of the Matt's script archive guestbook.pl

Any ideas?
Avatar of robysath
robysath

I noticed that you are putting $escaped{username} instead of $escaped{'username'}

and $escaped{realname} instead of $escaped{'realname'}
Avatar of uksupafly

ASKER

I've tried this and I'm afraid I still get the same problem.
Regarding first line:
" if ($inputs{username}){ "

if 'username' contains the e-mail (but none is entered by the user) then the very first if check fails and nothing will happen at all.
I think I understand - I thought it was saying that if there's an email address it should be linked to the realname, but if not, only the name should be printed.  But it presently states that it should only print if threre's an email address.

Is there a simple way to get what I need?
$_ .= qq(<a href="mailto:$escaped{username}">) if (defined $inputs{username} && $linkmail);
$_ .= "$escaped{realname}"
$_ .= "</a>" if (defined $inputs{username} && $linkmail);

if above doesn't work try:

$_ .= qq(<a href="mailto:$escaped{username}">) if (defined($inputs{username}) && $linkmail);
$_ .= "$escaped{realname}"
$_ .= "</a>" if (defined($inputs{username}) && $linkmail);
I've tried these but I get an error with both.

Here's the complete write guestbook section:

rewrite_file($guestbookreal, sub
{
   if (defined and /<!--begin-->/) {

     $_ = '' unless $entry_order;

     $_ .= "<b>Name:</b> ";

$_ .= qq(<a href="mailto:$escaped{username}">) if (defined($inputs{username}) && $linkmail);
$_ .= "$escaped{realname}"
$_ .= "</a>" if (defined($inputs{username}) && $linkmail);

     if ($inputs{'url'}) {
       $_ .= qq(<a href="$escaped{'url'}"> - Homepage</a>);
     } else {
       $_ .= " ";
     }

     $_ .= "<br />\n";

     if ($inputs{city}){
       $_ .= "<b>City:</b> $escaped{city} ";
     }

     if ($inputs{state}){
       $_ .= $escaped{state};
     }

     if ($inputs{country}){
       $_ .= "<b>Country:</b> $escaped{country}  ";
     }

     $_ .= "<br /><b>  Date:</b> $date<br />\n";

     if ($separator) {
       $_ .= "<b>Comments:</b> $comments<HR width=550 SIZE=3>\n\n";
     } else {
       $_ .= "<b>Comments:</b> $comments<p />\n\n";

     }

     $_ .= "<!--begin-->\n" unless $entry_order;
   }
});
This is the live version:

rewrite_file($guestbookreal, sub
{
   if (defined and /<!--begin-->/) {

     $_ = '' unless $entry_order;

     $_ .= "<b>Name:</b> ";

     if ($inputs{username}){
       if ($linkmail) {
         $_ .= qq(<a href="mailto:$escaped{username}">);
         $_ .= "$escaped{realname}</a>";
       } else {
         $_ .= "$escaped{realname}";
       }
     }

     if ($inputs{'url'}) {
       $_ .= qq(<a href="$escaped{'url'}"> - Homepage</a>);
     } else {
       $_ .= " ";
     }

     $_ .= "<br />\n";

     if ($inputs{city}){
       $_ .= "<b>City:</b> $escaped{city} ";
     }

     if ($inputs{state}){
       $_ .= $escaped{state};
     }

     if ($inputs{country}){
       $_ .= "<b>Country:</b> $escaped{country}  ";
     }

     $_ .= "<br /><b>  Date:</b> $date<br />\n";

     if ($separator) {
       $_ .= "<b>Comments:</b> $comments<HR width=550 SIZE=3>\n\n";
     } else {
       $_ .= "<b>Comments:</b> $comments<p />\n\n";

     }

     $_ .= "<!--begin-->\n" unless $entry_order;
   }
});
Oops, associative array, I should have said 'exists' instead of 'defined', try that instead.
I'm still getting a script error:

syntax error at guestbook.pl line 217, near "$_ " syntax error at guestbook.pl line 251, near "}" Execution of guestbook.pl aborted due to compilation errors
try:

     if (($inputs{username}) and ($linkmail)) {
         $_ .= qq(<a href="mailto:$escaped{username}">);
         $lmail = 1;
     }
     $_ .= "$escaped{realname}";
     if ($lmail) { $_ .= "</a>"; }
Instead of:

if ($lmail) { $_ .= "</a>"; }

you can also say:

$_ .= "</a>" if ($lmail);
Thanks again but I'm afraid I'm still getting errors:

Global symbol "$lmail" requires explicit package name at guestbook.pl line 217. Global symbol "$lmail" requires explicit package name at guestbook.pl line 220. BEGIN not safe after errors--compilation aborted at guestbook.pl line 682
ASKER CERTIFIED SOLUTION
Avatar of robysath
robysath

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That's it!   thanks very much, works a treat.