|
From: Kuna on 27 Dec 2006 04:06 Hi All, I am trying to use Java script to validate the form fields. The code is written in Perl and it is having a .pm extension for this form also there is a index.pl file which is containing the "Save" button and the form is posting the data to index.pl file and then it again comes to the methods written in the .pm file which is validating the form using server side code and submit that. But I am not able to get that where to do the Java script validation that will validate the form in the client side. Here I am having some codes that will give some idea about my form. <code> print "<body> <table width='100%' border='0' cellspacing='0' cellpadding='0'> <tr> <td width='22%' height='18'><img src='./images/logo_mmna.jpg' width='227' height='57'></td> <td width=''3%'> </td> <td width='49%'> <div align='center' class='v10b'><span class='style3'>" . $self->getText("NOTICE OF DESIGN PROCESS CHANGE") . "</span><br> </div></td> <td width='26%' valign='top'><table width='100%' border='0' cellspacing='0' cellpadding='0'> <!--DWLayoutTable--> <tr> <td height='18' colspan='3'> </td> </tr> <tr> <td width='20%' height='18' class='v10b'><label>" . $self->getText("Date:") . " </label></td> <td width='17%'>"; print hidden( -name => '.formId', -value => '4MChange', -tabindex => '-1', -override => 1 ); print textfield( -name => 'txt-date', -value => $self->retSysTime, -id => 'txt-date', -class => 'formelements', -size => '10', -title => 'Today\'s date', -tabindex => $tabindex ).'*'; foreach my $thisLabel (@singleEntryFields) { $result->{$thisLabel} = textfield( -name => sprintf( "txt-%s", $thisLabel ), -value => $data{$thisLabel}, -id => sprintf( "txt-%s", $thisLabel ), -class => ( $errLabel eq $thisLabel ) ? 'formmsg' : 'formelements', -size => $sizeHash{$thisLabel}, -title => $titleHash{$thisLabel}, -force => 1 ); } print "<td> <td height=\"10\" colspan=\"3\"><img src=\"/images/spacer.gif\" width=\"5\" height=\"8\"></td> </tr> <tr> <td height=\"18\"></td> <td colspan=\"2\"> </td> </tr> </table></td> </tr> <tr> <td height=\"18\" colspan=\"4\"> </td> </tr> <tr valign=\"top\"> <td height=\"14\" colspan=\"4\"><div align=\"left\" class=\"v10b\"><label>" . $self->getText('* indicates a field is required') . "</label></div>"; print p(); "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#E9E9E9\"> <tr> <td width=\"35%\" valign=\"top\"><table width=\"100%\" border=\"0\" align=\"left\" cellpadding=\"0\" cellspacing=\"0\"> <tr> <td width=\"22%\"><div align=\"right\" class=\"v10b\"><label>" . $self->getText("Supplier Name") . "</label>: </div></td> <td width=\"20%\">"; $tabindex++; print $result->{'sname'}.'*'; print "</td> </tr> <tr> <td colspan='2'><img src='/images/spacer.gif' width='5' height='8'></td> </tr> <tr> <td><div align='right' class='v10b'><label>" . $self->getText("Supplier Code:") . "</label> </div></td> <td align ='left'>"; $tabindex++; print $result->{'scode'}.'*'; print "</td> </tr> </table></td> <td width='35%' valign=\"top\"> <table width='100%' border='0' align='left' cellpadding='0' cellspacing='0'> <tr> <td width='28%'><div align='right' class='v10b'><label>" . $self->getText("Supplier Contact:") . " </label> </div></td> <td width='14%'>"; $tabindex++; print $result->{'scontact'}.'*'; print "</td> </tr> <tr> <td colspan='2'><img src='/images/spacer.gif' width='5' height='8'></td> </tr> <tr> <td><div align='right' class='v10b'><label>" . $self->getText("Supplier Fax:") . " </label></div></td> <td align='left'>"; $tabindex++; print $result->{'sfax'}.'*'; print "</td> </tr> </table></td> <td width='30%' valign=\"top\"> </code> This the form in the .pm file and in the index.pl is having the button as below: <code> if ( param() ) { $act = $cgi->param('act') || "preprocess"; $button = $cgi->param('button') || 'Save'; $no = ( defined $cgi->param('.no') ) ? ( $cgi->param('.no') ) : $defaultNo; $tloc = $cgi->param('.tloc'); $tsvData = $cgi->param('data'); my $error; $formId = ( defined $cgi->param('.formId') ) ? $cgi->param('.formId') : $formId; my $ev = sprintf 'use ACI::WebForms::Form%s; $thisform = new ACI::WebForms::Form%s();', $formId, $formId; if ( !eval $ev ) { die $@; } <./code> So what I am not able to get that since I am new to Perl, so I am not getting any <form> tag where I can use the Java script call. Also I am not getting any solution where to add the Java script that will take the form input data and validate it. Sorry if I had missed any information....Please look into this I need a urgent help....... Thanks and Regards, Kuna
From: Tad McClellan on 27 Dec 2006 06:47 Kuna <kunanu(a)gmail.com> wrote: > I am trying to use Java script I doubt that. I expect you are trying to use JavaScript. > to validate the form fields. The code is > written in Perl and it is having a .pm extension for this form also > there is a index.pl file which is containing the "Save" button and the > form is posting the data to index.pl file and then it again comes to > the methods written in the .pm file which is validating the form using > server side code and submit that. But I am not able to get that where > to do the Java script validation that will validate the form in the > client side. You must rewrite the .pm routines in JavaScript, then from Perl you print() the JavaScript code at the appropriate place. > -name => sprintf( "txt-%s", $thisLabel ), It is an abuse to use s(tring)printf(ormated) when you are not applying any formatting. -name => "txt-$thisLabel", > $formId = > ( defined $cgi->param('.formId') ) ? $cgi->param('.formId') : > $formId; That is a strange way to say: $formId = $cgi->param('.formId') if defined $cgi->param('.formId'); > my $ev = sprintf > 'use ACI::WebForms::Form%s; $thisform = new > ACI::WebForms::Form%s();', > $formId, $formId; If the module is designed to be used this way, then it is very poorly designed. > if ( !eval $ev ) { > die $@; > } Using that form of eval() is very very dangerous! You had better add some taint checking (perldoc perlsec) or prepare to be hacked. > So what I am not able to get that since I am new to Perl, The only piece of Perl knowledge that you need to accomplish this is how to use the print() function. You need JavaScript knowledge to know what you want to print(). > Please look into this I need a > urgent help....... Pleading is counter-productive. Have you seen the Posting Guidelines that are posted here frequently? -- Tad McClellan SGML consulting tadmc(a)augustmail.com Perl programming Fort Worth, Texas
From: Mark Clements on 27 Dec 2006 13:16 Tad McClellan wrote: > Kuna <kunanu(a)gmail.com> wrote: > >> I am trying to use Java script > > > I doubt that. > > I expect you are trying to use JavaScript. > > >> to validate the form fields. The code is >> written in Perl and it is having a .pm extension for this form also >> there is a index.pl file which is containing the "Save" button and the >> form is posting the data to index.pl file and then it again comes to >> the methods written in the .pm file which is validating the form using >> server side code and submit that. But I am not able to get that where >> to do the Java script validation that will validate the form in the >> client side. > > > You must rewrite the .pm routines in JavaScript, then from Perl > you print() the JavaScript code at the appropriate place. As an addendum to this, CGI::FormBuilder can be used to do a lot of the heavy lifting. It will, among other things, generate HTML forms and the Javascript code necessary for client-side validation. The learning curve may be a little steep, however. Mark
From: Ted Zlatanov on 27 Dec 2006 16:02 On 27 Dec 2006, mark.clementsREMOVETHIS(a)wanadoo.fr wrote: Tad McClellan wrote: > Kuna <kunanu(a)gmail.com> wrote: > >>> I am trying to use Java script >> I doubt that. >> >> I expect you are trying to use JavaScript. >> >> >>> to validate the form fields. The code is >>> written in Perl and it is having a .pm extension for this form also >>> there is a index.pl file which is containing the "Save" button and the >>> form is posting the data to index.pl file and then it again comes to >>> the methods written in the .pm file which is validating the form using >>> server side code and submit that. But I am not able to get that where >>> to do the Java script validation that will validate the form in the >>> client side. >> >> >> You must rewrite the .pm routines in JavaScript, then from Perl >> you print() the JavaScript code at the appropriate place. > > As an addendum to this, CGI::FormBuilder can be used to do a lot of > the heavy lifting. It will, among other things, generate HTML forms > and the Javascript code necessary for client-side validation. The > learning curve may be a little steep, however. I should mention for beginners' benefit that Javascript validation is nothing but a courtesy to the user. If you don't validate the data on the server, you are asking for trouble. Anyone can submit form data directly, bypassing the Javascript checks. So the server needs to reply with the same form, with the submitted valid values filled in, and the invalid ones marked. It's annoying, and I would agree with Mark Clements that CGI::FormBuilder does much of this and should be the first choice in most simple situations. Unfortunately some database setups may need dedicated code for form validation, to ensure atomic operations for example (so validation and insertion happen at the same time, which is not the CGI::FormBuilder model). Ted
|
Pages: 1 Prev: DHCP server Next: Cannot print images with Win32::Printer |