Link to home
Start Free TrialLog in
Avatar of spectropro
spectropro

asked on

Calling a script from html

I am currently learning perl.  I am working with a free script of an auction which seems to be pretty good at teaching how things work.

I can't, for some reason, figure out the proper way to call sections of the perl script from a web page that I create.  I want to eliminate much of the built in html and use my own style and formats.  

How do I do this?  Say I want it to look just like ebay for example.  On my page, I have a table that has 3 columns and 1 row.  I want the categories to appear in the first column along with the number of items next to them.  I have tried several things, and none work.  There must be a way to do this, and any help much appreciated.  I have seen others do exactly what I wish to do, but for some odd reason, they won't reply to my requests for how to do this..

I wasn't sure exactly how much space I could use for the question thus, no code..um...  I as of yet have NO html coded for it, since I wasn't sure how to do this.  I had a friend once that did it once for me, and he knew how, but damned it I can make it work again and can't get hold of him.  

The code is HUGE in the script and as you can imagine, there are however many if then statements for just the stuff you talked about...ie:  

local %form = &get_form_data;
if ($form{'action'} eq 'new') { &new; }
elsif ($form{'action'} eq 'repost') { &new; }
elsif ($form{'action'} eq 'procnew') { &procnew; }
elsif ($form{'action'} eq 'procbid') { &procbid; }
elsif ($form{'action'} eq 'reg') { ® }
elsif ($form{'action'} eq 'procreg') { &procreg; }
elsif ($form{'action'} eq 'creg') { &creg; }
elsif ($form{'action'} eq 'proccreg') { &proccreg; }
elsif ($form{'action'} eq 'closed') { &viewclosed1; }
elsif ($form{'action'} eq 'closed2') { &viewclosed2; }
elsif ($form{'action'} eq 'closed3') { &viewclosed3; }
elsif ($form{'action'} eq 'admin') { &admin; }
elsif ($form{'action'} eq 'procadmin') { &procadmin; }
elsif ($form{'action'} eq 'search') { &procsearch; }
elsif ($form{'item'} eq int($form{'item'}) and $category{$form{'category'}}) { &dispitem; }
elsif ($category{$form{'category'}}) { &displist; }

elsif ($form{'action'} eq 'lp') { &lp; }    #lost password form
elsif ($form{'action'} eq 'lp2') { &lp2; }  # processes lost password

elsif ($form{'action'} eq 'la') { &la; }    #lost alias form
elsif ($form{'action'} eq 'la2') { &la2; }  # processes lost alias

else { &dispcat; }

So, calling the areas isn't impossible.  I know how to edit it to add stuff also, as I have added several of the sections there.  My problem is, in the html coding, I can't remember how to call those sections..  I know I can type in a browser something like:  http://www.mysite.com/cgi-bin/auction.pl?action=lp2    

and that would goto the page for lost passwords..  I can't think of how to do this from within a page though.  Just typing that in shows that.  I can make a link of it also.  But, how do I make that page show up inside another page.  I put it (or want it) to show up inside a table so it is exactly where I want it to be on the page.

If that makes more sense, I would appreciate the help on that.  If not, I guess I am out of luck..  

Thanks for the help in advance...
This link here will take you to a page that I made that hopefully will let you see what I am wanting to do..

http://www.spectrografx.com/moria/index.shtml
Greg
Avatar of guadalupe
guadalupe

First calling "sections" of a perl script technically speaking is not possible.  However what you could do is call the script with different parameters in the query string which indicate which section of the script is the execute.  Something like this:

http://www.mydomain.com/cgi-bin-myscript.cgi?section=show_table

Then in your script:

#!/usr/bin/perl

&parseInput;


if ($fields eq "show_table")
{
      &show_table;  #Call subroutine show_table
}
elsif ($fields eq "some_other_sub")
{
      &some_other_sub; #Call some other sub!
}
else
{
      #Unknow or default case....
}


#---------------------------------Parse Input---------------------------------------#
#                  Arguments:      NONE                                                                                    #
#                  Purpose            Standard Form/Query String Parsing                                          #
#                  Calls:            NONE                                                                                    #
#-----------------------------------------------------------------------------------#

sub parseInput()
{
      #Parse form variables
      if ($ENV{'REQUEST_METHOD'} eq "POST")
      {
            read(STDIN, $temp, $ENV{'CONTENT_LENGTH'});
      }

      elsif ($ENV{'REQUEST_METHOD'} eq "GET" )
      {
            $temp = $ENV{'QUERY_STRING'};
      }

      @pairs=split(/&/,$temp);
      
      foreach $item(@pairs)
      {
            ($key,$content)=split (/=/,$item,2);
            $content=~tr/+/ /;
            $content=~ s/%(..)/pack("c",hex($1))/ge;
            $fields{$key}=$content;
      }

}



About the table I can't really help with seeing the code and understanding a little better what you want to do.  You talk about displaying data in a certain way but I have no idea where the data is.  Does it come from a database, a flat text file...??  Where is it?  In an array? A Hash?

A little more info and some code would help.

 
spectropro ,

can you post the perl code you have here?

that way we can provide you with a much more accurate answer.

Sorry there was a small error in my code:

if ($fields{'section'} eq show_table")
{
&show_table;  #Call subroutine show_table
}
elsif ($fields'section'}eq "some_other_sub")
{
&some_other_sub; #Call some other sub!
}
else
{
#Unknow or default case....
}

My apologies.
Avatar of spectropro

ASKER

Edited text of question.
Edited text of question.
Hi Greg,

i looked at http://www.spectrografx.com/moria/index.shtml  page.

Here is my understanding of your requirements.

* you want the index.shtml page to be generated dynamically.
* Also in that page you have a set of categories which should again be hyperlinks to a script (Eg. http://www.mysite.com/cgi-bin/auction.pl?action=categories).

* Now when the user clicks on any category, you want a HTML page to be generated for that category.

* Finally since your index.shtml page itself is dynamic it will be as simple as adding a new category and the hyperlink for that category (with the link to the aution.pl script) will be automatically created.

Pl. let me know if this is indeed the case.

Thanks
maneshr:

hmmm..  Essentially that is correct.  However, I was going to create the front page myself.  And where the list of categories should go, that would be called from the script dynamically.  

Then, when a cat is clicked on, those pages from there on would be created on the fly.  I just can't figure out how in that front page that I will create myself, how to make the script show me the categories without me having to type them in with links to the script.  I want the script to actually post the list of categories..

Thanks.

greg
here is what i would suggest .

you create the hard-coded html template file by hand. now whereever you want the categories to appear you put some kind of placeholder (Eg <!--dynamic file goes here-->)

Also you have some kind of text file where you would have a list of the categories and the hyperlinks that would go against each category.

Eg.

books|http://wns.com/cgi-bin/auction.pl?cat=books
toys|http://wns.com/cgi-bin/auction.pl?cat=toys

etc...

Finally you have a PERL script that you can run from the command prompt. This script would read the template and when it encounters the placeholder, generate the hyperlinks of categories and put them in a your final html file.

so all that you have to do when you have a new category is add an entry to the text file and run your PERL script!!

let me know your thoughts on the same.
Excellant idea.  I will do that.  Maybe...hehe

Any chance you can lend a hand with the script that would call the text file in??  And if all that is done, how would it call it without human intervention?  Am I looking at having to use a SSI?  Not a problem if so, just currious.
ASKER CERTIFIED SOLUTION
Avatar of maneshr
maneshr

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
Thanks maneshr...  can you please email me directly??

gregs@spectrografx.com
can you pl. tell me the exact requirements??

that way i know what to code for.

Thanks.
maneshr,   How about I directly email you the script and you will probably understand more of what needs to happen when you see it.  You can mail me at:

gregs@spectrografx.com and I will send the script back to you via email.

Greg
email me at maneshr@hotmail.com