Solved

NMS Guestbook problem

Posted on 2003-10-22
14
1,124 Views
Last Modified: 2013-12-25
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?
0
Comment
Question by:uksupafly
  • 7
  • 7
14 Comments
 
LVL 1

Expert Comment

by:robysath
ID: 9634931
I noticed that you are putting $escaped{username} instead of $escaped{'username'}

and $escaped{realname} instead of $escaped{'realname'}
0
 

Author Comment

by:uksupafly
ID: 9635243
I've tried this and I'm afraid I still get the same problem.
0
 
LVL 1

Expert Comment

by:robysath
ID: 9635810
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.
0
 

Author Comment

by:uksupafly
ID: 9638114
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?
0
 
LVL 1

Expert Comment

by:robysath
ID: 9639942
$_ .= 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);
0
 

Author Comment

by:uksupafly
ID: 9640819
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;
   }
});
0
 

Author Comment

by:uksupafly
ID: 9640827
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;
   }
});
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 1

Expert Comment

by:robysath
ID: 9642372
Oops, associative array, I should have said 'exists' instead of 'defined', try that instead.
0
 

Author Comment

by:uksupafly
ID: 9642940
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
0
 
LVL 1

Expert Comment

by:robysath
ID: 9653414
try:

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

Expert Comment

by:robysath
ID: 9653431
Instead of:

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

you can also say:

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

Author Comment

by:uksupafly
ID: 9654511
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
0
 
LVL 1

Accepted Solution

by:
robysath earned 250 total points
ID: 9654824
Then try:

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

Author Comment

by:uksupafly
ID: 9654896
That's it!   thanks very much, works a treat.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now