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{user name}">);
$_ .= "$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?
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{user
$_ .= "$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?
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.
" 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.
ASKER
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?
Is there a simple way to get what I need?
$_ .= qq(<a href="mailto:$escaped{user name}">) if (defined $inputs{username} && $linkmail);
$_ .= "$escaped{realname}"
$_ .= "</a>" if (defined $inputs{username} && $linkmail);
if above doesn't work try:
$_ .= qq(<a href="mailto:$escaped{user name}">) if (defined($inputs{username} ) && $linkmail);
$_ .= "$escaped{realname}"
$_ .= "</a>" if (defined($inputs{username} ) && $linkmail);
$_ .= "$escaped{realname}"
$_ .= "</a>" if (defined $inputs{username} && $linkmail);
if above doesn't work try:
$_ .= qq(<a href="mailto:$escaped{user
$_ .= "$escaped{realname}"
$_ .= "</a>" if (defined($inputs{username}
ASKER
I've tried these but I get an error with both.
Here's the complete write guestbook section:
rewrite_file($guestbookrea l, sub
{
if (defined and /<!--begin-->/) {
$_ = '' unless $entry_order;
$_ .= "<b>Name:</b> ";
$_ .= qq(<a href="mailto:$escaped{user name}">) 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;
}
});
Here's the complete write guestbook section:
rewrite_file($guestbookrea
{
if (defined and /<!--begin-->/) {
$_ = '' unless $entry_order;
$_ .= "<b>Name:</b> ";
$_ .= qq(<a href="mailto:$escaped{user
$_ .= "$escaped{realname}"
$_ .= "</a>" if (defined($inputs{username}
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;
}
});
ASKER
This is the live version:
rewrite_file($guestbookrea l, sub
{
if (defined and /<!--begin-->/) {
$_ = '' unless $entry_order;
$_ .= "<b>Name:</b> ";
if ($inputs{username}){
if ($linkmail) {
$_ .= qq(<a href="mailto:$escaped{user name}">);
$_ .= "$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;
}
});
rewrite_file($guestbookrea
{
if (defined and /<!--begin-->/) {
$_ = '' unless $entry_order;
$_ .= "<b>Name:</b> ";
if ($inputs{username}){
if ($linkmail) {
$_ .= qq(<a href="mailto:$escaped{user
$_ .= "$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.
ASKER
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
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{user name}">);
$lmail = 1;
}
$_ .= "$escaped{realname}";
if ($lmail) { $_ .= "</a>"; }
if (($inputs{username}) and ($linkmail)) {
$_ .= qq(<a href="mailto:$escaped{user
$lmail = 1;
}
$_ .= "$escaped{realname}";
if ($lmail) { $_ .= "</a>"; }
Instead of:
if ($lmail) { $_ .= "</a>"; }
you can also say:
$_ .= "</a>" if ($lmail);
if ($lmail) { $_ .= "</a>"; }
you can also say:
$_ .= "</a>" if ($lmail);
ASKER
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That's it! thanks very much, works a treat.
and $escaped{realname} instead of $escaped{'realname'}