Home: Perl Programming Help: Beginner:
HTML/Perl dropdown form problem



Dingo
Novice

Aug 27, 2010, 1:19 PM


Views: 34579
HTML/Perl dropdown form problem

I'm having a problem calling a simple perl script. When I click the go button in the HTML it sends me to "/cgi/redir.pl" instead of the URL held in the value.

I'm using the Perl script found on this page. http://www.chami.com/tips/internet/042999I.html

Thanks for any help in advance!!!

Here is the script and HTML.


Code
  
#!/usr/bin/perl

sub xcgi_InitForm
{
my($h) = '[a-fA-F0-9]';
my($buff, @params, $param);
my($param_name, $param_value);
local(*xcgi_form) = @_ if @_;

read(STDIN, $buff, $ENV{'CONTENT_LENGTH'});

@params = split(/&/, $buff);

foreach $param (@params)
{
($param_name, $param_value) = split(/=/, $param);

$param_value =~ tr/+/ /;
$param_value =~ s/%($h$h)/pack("C",hex($1))/eg;

$xcgi_form{$param_name} = $param_value;
}
}

{
my(@form);

xcgi_InitForm(*form);

$url = $form{'url'};
print "Location: $urlnn";
}


Here is the HTML

Code
<form method="post" action="/cgi/redir.pl"> 
<select name="url">
<option value="http://www.google.com">Alabama</option>
</select>
<input type="submit" value="Go" />
</form>



Zhris
Enthusiast

Aug 27, 2010, 2:05 PM


Views: 34575
Re: [Dingo] HTML/Perl dropdown form problem

Hi,


Code
<form method="post" action="/cgi/redir.pl">


Change the action to point to the actual location of your script.

Chris


(This post was edited by Zhris on Aug 27, 2010, 2:21 PM)


Dingo
Novice

Aug 27, 2010, 2:21 PM


Views: 34567
Re: [Zhris] HTML/Perl dropdown form problem

Thanks Chris!

I tried including the complete URL http://www.exampleurl.com/cgi/redir.pl instead of "/cgi/redir.pl" and got the same thing.... Dang.

The dropdown menu (the form) is in the HTML but I tried the $url anyway and it didn't work.

I'm totally stumped. Is there another thing that I could check?


(This post was edited by Dingo on Aug 27, 2010, 2:22 PM)


Dingo
Novice

Aug 27, 2010, 2:24 PM


Views: 34565
Re: [Zhris] HTML/Perl dropdown form problem

Chris,

Is there a simple perl script I could put on my server and in my HTML to see if Perl is working in the first place?


Zhris
Enthusiast

Aug 27, 2010, 2:29 PM


Views: 34563
Re: [Dingo] HTML/Perl dropdown form problem

Hey,

Try the following, ensure the permissions are set to 755. Run the script directly e.g. http://domain.com/script.pl or http://domain.com/cgi-bin/script.pl etc.

script.pl

Code
#!/usr/bin/perl 
print "Content-type: text/html\n\n";
print "Hello world<br />";


Chris


(This post was edited by Zhris on Aug 27, 2010, 2:30 PM)


Zhris
Enthusiast

Aug 27, 2010, 2:35 PM


Views: 34559
Re: [Dingo] HTML/Perl dropdown form problem

When you say its not working, do you mean you are getting a perl error e.g. Error 500, or page not found etc? Excluding the "exampleurl" part, is "http://www.exampleurl.com/cgi/redir.pl" definately the url to your perl script?

Chris


(This post was edited by Zhris on Aug 27, 2010, 2:37 PM)


Dingo
Novice

Aug 27, 2010, 2:36 PM


Views: 34558
Re: [Zhris] HTML/Perl dropdown form problem

Hi Chris,

This might sound like a stupid question but what do I put in the HTML?


Dingo
Novice

Aug 27, 2010, 2:37 PM


Views: 34556
Re: [Zhris] HTML/Perl dropdown form problem

I was getting

500 Internal Server Error

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, support@supportwebsite.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.


(This post was edited by Dingo on Aug 27, 2010, 2:38 PM)


Zhris
Enthusiast

Aug 27, 2010, 2:38 PM


Views: 34555
Re: [Dingo] HTML/Perl dropdown form problem

The perl script is creating the HTML for you (the test one I provided). You don't need to create a seperate HTML document, just run the script directly from your browser (script.pl).

Chris


Zhris
Enthusiast

Aug 27, 2010, 2:39 PM


Views: 34553
Re: [Dingo] HTML/Perl dropdown form problem

Ok error 500 will mean there is something wrong with your script or configuration. Firstly have you ensured that permissions are set to 755 and that you are uploading the file in ASCII format?

Chris


Dingo
Novice

Aug 27, 2010, 2:41 PM


Views: 34551
Re: [Zhris] HTML/Perl dropdown form problem

Yep, same 500 error on your script.

The problem must not be the code. I'm saving my perl in notepad under ANSI format. Could it be that or something liket that?


(This post was edited by Dingo on Aug 27, 2010, 2:42 PM)


Dingo
Novice

Aug 27, 2010, 2:43 PM


Views: 34548
Re: [Zhris] HTML/Perl dropdown form problem

Aaaaah....

Ok I'll start saving to ASCII. Where do I set permissions 755?

THANK YOU SO MUCH!!!!


(This post was edited by Dingo on Aug 27, 2010, 2:44 PM)


Zhris
Enthusiast

Aug 27, 2010, 2:48 PM


Views: 34544
Re: [Dingo] HTML/Perl dropdown form problem

I'm unfamiliar with ANSI, I can't tell if will it be an issue. If you search "perl error 500" in google, you will find a few different pages providing guidelines in determining the likely cause of this error, and how to fix it. Its one of those problems thats sometimes difficult to help someone with without further information such as host etc.

Chris


(This post was edited by Zhris on Aug 27, 2010, 2:50 PM)


Dingo
Novice

Aug 27, 2010, 2:50 PM


Views: 34541
Re: [Zhris] HTML/Perl dropdown form problem

Actually maybe the problem is my uploader. I'm just copying files between windows.

Do I need a special program to send it to the server in ASCII?


Zhris
Enthusiast

Aug 27, 2010, 2:51 PM


Views: 34538
Re: [Dingo] HTML/Perl dropdown form problem

Usually files are uploaded via an FTP client, if you are using an FTP client, there will be an option to ensure files are uploaded in this format.

Chris


Zhris
Enthusiast

Aug 27, 2010, 3:03 PM


Views: 34527
Re: [Dingo] HTML/Perl dropdown form problem

I'm a little bit confused:


Quote
When I click the go button in the HTML it sends me to "/cgi/redir.pl" instead of the URL held in the value.


Which sounds as if the script originally ran for you, without any errors?

Chris


Dingo
Novice

Aug 27, 2010, 3:07 PM


Views: 34525
Re: [Zhris] HTML/Perl dropdown form problem

More specifically I get the 500 Internal Server Error and at the same time I get "/cgi/redir.pl" in the address line of my browser.

Uggh...

My site is hosted on GoDaddy. Dang.



I just tried a program called Classic FTP. It didn't have an option for ASCII but I assume it knew to upload a .pl file in ASCII.


(This post was edited by Dingo on Aug 27, 2010, 3:08 PM)


Zhris
Enthusiast

Aug 27, 2010, 3:09 PM


Views: 34522
Re: [Dingo] HTML/Perl dropdown form problem

GoDaddy, does your account use Hosting Config 2.0 ?

http://help.godaddy.com/topic/424/article/1574

Chris


(This post was edited by Zhris on Aug 27, 2010, 3:15 PM)


Dingo
Novice

Aug 27, 2010, 3:29 PM


Views: 34508
Re: [Zhris] HTML/Perl dropdown form problem

Thanks for the link Chris!

I just checked and I'm using Hosting Configuration 2.2 which looks like it's new.

Here is the test pl doc from the Godaddy page.

#!/usr/bin/perl

use CGI qw(:standard); print "Content-type: text/html\n\n";
print "Greetings user.\n";

So if I name it script.pl, upload it in ASCII to the bin and then type in... www.myurl.com/bin/script.pl it should work?


Zhris
Enthusiast

Aug 27, 2010, 3:32 PM


Views: 34507
Re: [Dingo] HTML/Perl dropdown form problem

Just to add,

I've searched around, and it seems as if many people have difficulties running perl scripts with GoDaddy. It is suggested to check your server error logs, or contact GoDaddy for advise on solving your issue / consult their documentation.

Chris


Zhris
Enthusiast

Aug 27, 2010, 3:35 PM


Views: 34506
Re: [Dingo] HTML/Perl dropdown form problem

It would be a good idea to try that script, although I can't see how "use CGI qw(:standard);" will fix this issue, although you never know.


Quote
So if I name it script.pl, upload it in ASCII to the bin and then type in... www.myurl.com/bin/script.pl it should work?


In theory, that should work, I thought you had already tried this, except with "my" test script.

Chris


(This post was edited by Zhris on Aug 27, 2010, 3:37 PM)


Dingo
Novice

Aug 27, 2010, 3:37 PM


Views: 34502
Re: [Zhris] HTML/Perl dropdown form problem

Thanks for helping Chris. At least I've got it narrowed down.

I can't believe how hard it is to load and test a simple file! Damn you GODADDY!!!

@!%#@!#$@!$#@!#$


(This post was edited by Dingo on Aug 27, 2010, 3:38 PM)


Dingo
Novice

Aug 27, 2010, 3:39 PM


Views: 34499
Re: [Zhris] HTML/Perl dropdown form problem

BTW I tried the Godaddy script and it didn't work.

What the heck, the default Godaddy setting is perl off?!? I gotta contact them.


Zhris
Enthusiast

Aug 27, 2010, 3:41 PM


Views: 34497
Re: [Dingo] HTML/Perl dropdown form problem

Have you checked your error logs first, they may give you a clue as to why you recieve error 500? Does the GoDaddy control panel provide a CGI output monitor? Did you manage to try checking if permissions were set to 755? Afterall, GoDaddy support must be able to help you run your first perl script.

Chris


(This post was edited by Zhris on Aug 27, 2010, 3:49 PM)


Dingo
Novice

Aug 27, 2010, 3:51 PM


Views: 34492
Re: [Zhris] HTML/Perl dropdown form problem

Ok, I just turned on error logs. (it was off before)

How can I use this to test my problem?


Zhris
Enthusiast

Aug 27, 2010, 3:57 PM


Views: 13133
Re: [Dingo] HTML/Perl dropdown form problem

Run your script again and see if anything appears in the error log.

Chris


Dingo
Novice

Aug 27, 2010, 4:00 PM


Views: 13132
Re: [Zhris] HTML/Perl dropdown form problem

Maybe it takes a while to turn on. Right now I think my log is empty.

Do you recommend an FTP client?

I'm using ClassicFTP and I don't see a set permissions option for files.


Zhris
Enthusiast

Aug 27, 2010, 4:03 PM


Views: 13130
Re: [Dingo] HTML/Perl dropdown form problem

If you right click the perl script, does a menu come up, if so, it may say permissions, or permissions might be under properties or options etc. I use FireFTP from Mozilla Firefox.

Chris


Dingo
Novice

Aug 27, 2010, 4:03 PM


Views: 13130
Re: [Zhris] HTML/Perl dropdown form problem

Hey I've got an idea. Can I host and run a perl file locally on my hard drive?

I see this line at the beginning of my file. Could I change it to something else and test perl locally?

#!/usr/bin/perl


Dingo
Novice

Aug 27, 2010, 4:06 PM


Views: 13128
Re: [Zhris] HTML/Perl dropdown form problem

Ok right on, I just logged in using Firefox.

I see my file, script.pl. I just right clicked and all I have is properties which doesn't tell me much of anything.

I'm going to go get that FTP program you use and try that.


Zhris
Enthusiast

Aug 27, 2010, 4:09 PM


Views: 13125
Re: [Dingo] HTML/Perl dropdown form problem

Its just a Firefox "add on", click tools, add-ons, and search for Fire FTP (unless you already knew this). Its a very nice clean FTP client. I'm unsure that this is going to help solve your problem, after reading about others issues with Perl and GoDaddy [:D].

Chris


Dingo
Novice

Aug 27, 2010, 4:12 PM


Views: 13123
Re: [Zhris] HTML/Perl dropdown form problem

Pirate I think I'm going to cry

http://fireftp.mozdev.org/

FireFTP is not compatible with Firefox 3.0.19

Ah well, maybe it wouldn't have helped.


Zhris
Enthusiast

Aug 27, 2010, 4:19 PM


Views: 13121
Re: [Dingo] HTML/Perl dropdown form problem

Hah, thats an oldish Firefox! I assume you are using XP?. This thread is starting to get quite big, with multiple issues coming into play. If you wanted to get my email, send me a private message, and if you wanted continuous support in solving your issues we could talk via that.

Chris


Dingo
Novice

Aug 27, 2010, 4:20 PM


Views: 13119
Re: [Zhris] HTML/Perl dropdown form problem

Thank you so much Chris. I have to go now but that would be great.


Zhris
Enthusiast

Aug 27, 2010, 4:21 PM


Views: 13118
Re: [Zhris] HTML/Perl dropdown form problem

In regards to testing perl locally, you would need perl i.e. ActivePerl installed on your machine.

Chris


Zhris
Enthusiast

Aug 30, 2010, 6:29 AM


Views: 13084
Re: [Dingo] HTML/Perl dropdown form problem

Bumping this post up for a final time.

For anyone who was interested in the final solution, the O/P fixed his issue of running a perl script using GoDaddy by simply ensuring that he was uploading the script in ASCII format, and permissions set to 755. This advice was given way back in the thread, but the O/P was unable to ensure these settings via his old FTP client, which he has now upgraded to FireFTP.

Chris