Go Back   CodingForums.com > :: Server side development > Perl/ CGI

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-19-2012, 06:18 PM   PM User | #16
Malform11
New Coder

 
Join Date: Jan 2011
Location: Dallas
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Malform11 has a little shameless behaviour in the past
I'm sorry. It was your perl code. I named it:


Submitanswer.pl


Code:
#!/usr/bin/perl

use strict;
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser);  # remove this after debugging the script

my $cgi     = CGI->new;
my %params  = $cgi->Vars;
my $title   = "Get Information From A URL";

print $cgi->header,
      $cgi->start_html($title),
      $cgi->h1($title),
      $cgi->hr;
      
foreach my $name ( keys %params ) {
    print $cgi->p("Name = $name, Value = $params{$name}\n");
}
print $cgi->end_html;
Malform11 is offline   Reply With Quote
Old 02-19-2012, 09:50 PM   PM User | #17
FishMonger
Super Moderator


 
Join Date: May 2005
Location: Southern tip of Silicon Valley
Posts: 2,753
Thanks: 2
Thanked 149 Times in 144 Posts
FishMonger will become famous soon enoughFishMonger will become famous soon enough
It works correctly for me.

Are you calling the script directly in the browser, or are you filling in the form fields on the html page and submitting the form?
FishMonger is offline   Reply With Quote
Old 02-20-2012, 06:50 AM   PM User | #18
Malform11
New Coder

 
Join Date: Jan 2011
Location: Dallas
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Malform11 has a little shameless behaviour in the past
I go to the visitor form on one html page, called Visitor Form.html.
I submit info. I leave that page.
I open up my second web page with a secret name, that calls your perl routine. After clicking the button, it prints the heading and the horizontal row, but it doesn't print the info I submitted. I assume this page works and the other doesn't.
Malform11 is offline   Reply With Quote
Old 02-20-2012, 03:38 PM   PM User | #19
FishMonger
Super Moderator


 
Join Date: May 2005
Location: Southern tip of Silicon Valley
Posts: 2,753
Thanks: 2
Thanked 149 Times in 144 Posts
FishMonger will become famous soon enoughFishMonger will become famous soon enough
Why would you think that would do anything useful?

The Form.html page needs to submit the data directly to the perl script I provided, i.e., it's the script you point to in the action attribute of the form. Or, the script that it points to needs to save the data to a file or database and then some other script could read-in that data from that file or database.
FishMonger is offline   Reply With Quote
Old 02-20-2012, 11:40 PM   PM User | #20
Malform11
New Coder

 
Join Date: Jan 2011
Location: Dallas
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Malform11 has a little shameless behaviour in the past
back to square one

"Submit Visitor Info to text or hex file" was the title of this thread. That would have worked.

After a week i am advised that i am an idiot for thinking the perl was supposed to work.

If there is a way to make it work you are not going to tell me. Your sponsors sell visitor forms.
Malform11 is offline   Reply With Quote
Old 02-21-2012, 12:01 AM   PM User | #21
FishMonger
Super Moderator


 
Join Date: May 2005
Location: Southern tip of Silicon Valley
Posts: 2,753
Thanks: 2
Thanked 149 Times in 144 Posts
FishMonger will become famous soon enoughFishMonger will become famous soon enough
I did tell you what you needed to do (i.e., use the open function to open a filehandle and print the data to that filehandle), but due to the fact that you left out some very important details of what you were actually doing we ended up on a tangent.

Have you read the perldoc documentation that I pointed you to?

Do you still need help writing the data to the file? Which needs to be done by the script that the form is submitted to.

At this point, are looking to learn how to do this, or are you wanting someone else to write it for you?
FishMonger is offline   Reply With Quote
Old 02-26-2012, 09:45 AM   PM User | #22
Malform11
New Coder

 
Join Date: Jan 2011
Location: Dallas
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Malform11 has a little shameless behaviour in the past
approaching answer?

Thanks, I am starting to get this a little.
I think I debugged this, except line 16 gets error message I can't figure out.

Code:
#!/usr/bin/perl

use strict;
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser);  # remove this after debugging the script

my $cgi     = CGI->new;
my %params  = $cgi->Vars;
my $title   = "Information From Visitors";

open(my $fh, ">>", "visitorinput.txt")# ">>" for append?
or die "cannot open > visitorinput.txt: $!";
 
foreach my $name (keys %params) {
    print my $fh->("Name"=$name,"Value"=%params{$name});#error here?
}
close(my $fh)
|| warn "close failed: $!";
Malform11 is offline   Reply With Quote
Old 02-26-2012, 03:33 PM   PM User | #23
FishMonger
Super Moderator


 
Join Date: May 2005
Location: Southern tip of Silicon Valley
Posts: 2,753
Thanks: 2
Thanked 149 Times in 144 Posts
FishMonger will become famous soon enoughFishMonger will become famous soon enough
Code:
print $fh "Name=$name,Value=$params{$name}\n";
You also need to take the 'my' off the close satement.
FishMonger is offline   Reply With Quote
Old 02-27-2012, 07:37 AM   PM User | #24
Malform11
New Coder

 
Join Date: Jan 2011
Location: Dallas
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Malform11 has a little shameless behaviour in the past
hmmmm?

I changed the code. I went to visitor form, and entered info. It came back with some message, not like the error message, saying request not fulfilled or something. I opened the text file and the info was there, no problem. I changed the permission, maybe that will stop the message.

Thank you for getting this to work....
Malform11 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:52 AM.


Advertisement
Log in to turn off these ads.