Hey guys, I'm just messing around with a perl webpage. The idea is to make a simple validation form that will later insert a record into my DVD database. it's all very basic at the moment, and I worked up my script from the form validation example I found on this website: http://www.elated.com/articles/form-validation-wi
th-perl-and-cgi/ . When I put this script on my webserver, it works fine.
My form just has 3 text fields and a button. The problem is, when I enter text and try to submit, the text I entered dissapears and I get the error messages, stating that the boxes are empty. For the life of me, I can't figure out what is wrong with it. Mind you, I've just started learning PERL in bits and pieces, from examples I find on the web, so if I'm missing the obvious here, please don't shoot me .
Take with a grain of salt, I don't nomrally use perl in an OO fasion like you are here.
I think you might be getting caught up by the scoping of your CGI object.
I would suggest either passing it to the validate_form function or dropping the 'my' keyword when you create it.
I put this in my Web server, entered something and submit, and got
"Thank you - your form was submitted correctly!"
Is this your expected result? The posted script seems to look fine to me.
The debate between the procedural and the OO camp has always been there.
Personally I see nothing wrong with using OO-style in Perl. One major Perl-based discussion forum (I don't give the name here as it is semi-commercial) is fully OO, and IMO OO in Perl is nothing more than subroutines that happen to contain "instance" data with "packages" offering namespace separation. Neither of them I would agree being cited as hindrance rather than help. In fact, in recent years PHP is starting to aware they need this kind of things now when they attract more sophisticated developers who have experiences with other language environments.
Scoping in Perl can be complex, but once you understand it, it is a useful device to prevent variable collision and inadvertently stomping on global variables you don't intend to access. If you have happened to write any Perl thing that spans more than 50 script files or so, you will know this is far easier to happen than you would imagine.
By the way, it is a consensus in the Perl community that new code should be runnable with "use strict", and variables without explicitly marked 'my', 'our', or 'local' (with package qualification), will not pass the strict test.
Surely one is free to select his/her approach. My opinion is we should be open about others' choices even if we have a different stance personally.
That was indeed what I was aiming for, however, on my webserver it doesn't seem to work, whereas the example script in the link I posted does. If needed, I could pm a link to the script on my server. I don't really want to post it here, as it is just a private server in my house.
I can't figure out why one script would work fine, and the other wouldn't.
1) You previously mentioned the posted script didn't work, but my test of the script verbatim you said was what you intended to get;
2) You did not tell what are the differences between the script you deployed and the one you posted. Of course, you should post the simplest variation of your script, in full, that is sufficient to demonstrate and have others reproduce the problem.
I have not visited the link you provided, so I do not quite understand how I can help you with this. If you have further details to share, please feel free to post again.
The Code:
#!/usr/bin/perl
use strict;
use warnings;
print "Please enter numbers, separated by commas: ";
my $data=<STDIN>; chomp $data;
my @dataset=split(/,/, $data);
my $sum = 0;
foreach my $num (@dataset) {
$sum += $num;
}
my $total_nums = scalar(@dataset);
my $mean =... (1 Reply)
Hi every one,
Please excuse me if any grammatical mistakes is there.
I have multiple xml files in one directory, I need to create multiple XML files into one XML file.example files like this</p>
file1:bvr.xml
... (0 Replies)
My form validation script looks like this of the form like this....
<html>
<form method="POST" action="">
<table >
<tr>
<td >Name:</td>
<td ><input type="text" name="name" size="30%"></td>
</tr>
<tr>
<td >Phone:</td>
<td ><input type="text" name="phone" size="30%"></td>
</tr>... (0 Replies)
print "1.readfromfile\n2.add_ex1(4,5)\n3.add_ex2(11,5)\n4.add_ex3(9,3)\n5.add_ex4(91,4)\n";
How to do it in this form:
print "1.readfromfile\n
2.add_ex1(4,5)\n
3.add_ex2(11,5)\n
4.add_ex3(9,3)\n
5.add_ex4(91,4)\n"; (3 Replies)
Hi All,
I am doing a perl script validation for Phone numbers.
The normal phone number format is 01-32145.
I need to do two validations for the phone number
1) A valid phone number can have at least two digits as prefix and at least five digits as postfix. e.g. 01-01011
2) A... (5 Replies)
Hi
I have a successfullly run perl script (by issuing command "perl sub.pl" under shell mode) and this sub.pl will call sub.exp successfully. The sub.exp expect script is basically to login to a server and run some commands and put the output into a sub.txt file, it takes about 5 seconds to... (0 Replies)
Hi Everyone,
#!/usr/bin/perl
$a = ".a!";
if ($a =~ s///g) {
print "invalid file name\n";
} else {
print "valid file name\n";
}
but the output is:
Invalid range "_-." in regex; marked by <-- HERE in m// at ./a.pl line 5.
the linux file name should be A-Z, a-z,... (8 Replies)
hi,i hav a form in cgi perl script.this script accepts a value from user from another html form, and depending upon this value,i need to disable /enable radio buttons in cgi-perl script wen second page is displayed on executing cgi perl script.how do i do it using javascript? (0 Replies)
Hello All,
I was trying to come up with a form using perl cgi. I then created a frame to show the output of the form. Refer below
print $display_form->start_form(-title=>"Updateuser", -style => 'font-size: 9pt; color: #202020 ; font-family: Verdana', action=>"${DOCROOT}updateUser.pl",... (4 Replies)