Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Creating a link in mason

by davidov0009 (Scribe)
on Mar 22, 2007 at 04:02 UTC ( [id://605953]=note: print w/replies, xml ) Need Help??


in reply to Creating a link in mason

One suggestion I can think of that might make this HTML easier to create is to use CGI.pm and its href function like so:
# sample of href from CGI.pm use strict; use diagnostics; use CGI qw(:standard); my $id = CGI::escape(param('id')); print a({-href=>"removecard?card_id=$id"}, "Remove");

Here we loaded the CGI module with standard HTML functions and then assigned the variable $id to the posted variable for the id of the card the person wants to retrieve. (This would be sent to your script by a form or a query string and retrieved through the param() function)

Then we make sure the id will not create a malformed URL by using the CGI::escape() function to convert any characters to their hexadecimal equivalents.

Once this is done we are ready to create the HTML itself. This is done by printing out the return value from the a function, which creates the same HTML as an tag would. The link attributes are sent inside curly braces {} and are defined by the '-href' attribute. The value for the link is enclosed in double quotes ("") so that the $id variable will be interpolated by PERL and create the link to the card.

The last part of the a() function is the text displayed for the link on the page.

A more complete version of this script would need to create the starting and ending HTML and the neccessary header.

For a good general reference on CGI.pm I would suggest the modules manual page at CPAN: http://search.cpan.org/~lds/CGI.pm-3.27/CGI.pm

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://605953]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (1)
As of 2024-04-25 03:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found