hello monks,
I found node Re: Form validation - server-side (Dancer) and client-side (javascript) and I'm trying to use the mentioned module CGI::Ex::Validate. I'm trying to get it to work and the code below results in a HTML-Form included with Javascript for client-side. Happy with that, except that I can't seem to find out how to add code that gives me a simple set of radio-buttons. Is there anyone who has experience with that and cares to share information on that?
Thanks, Gert
#!/usr/bin/perl
#
use CGI::Ex::Validate;
my $val_hash = {
'group order' =>
[qw(date fname lname email email2 telephone choice comments)],
date => {
name => 'Date(s) of Workshop *', # field is not optional in
+ this case
required => 1,
match => 'm|^\d\d\d\d/\d\d/\d\d$|',
match_error => 'Please enter date in YYYY/MM/DD format',
custom_js => "function (args) {
var t = new Date();
var y = t.getYear()+1900;
var m = t.getMonth() + 1;
var d = t.getDate();)
if (m < 10) m = '0'+m;
if (d < 10) d = '0'+d;
(args.value > ''+y+'/'+m+'/'+d) ? 1 : 0;
}",
custom_js_error => 'The date was not greater than today.',
},
fname => {
name => 'First name *',
required => 1,
min_len => 2,
max_len => 50,
},
lname => {
name => 'Last name *',
required => 1,
min_len => 2,
max_len => 75,
},
email => {
name => 'Email *',
required => 1,
max_len => 100,
type => 'email',
type_error => '$name must be a valid email address.',
},
email2 => {
validate_if => 'email was_valid',
vif_disable => 1,
name => 'Verify email *',
required => 1,
equals => 'email',
},
telephone => {
name => 'Telephone *',
required => 1,
max_values => 1,
max_len => 14,
},
#
# attempt to create radio-buttons.
#
'group order'=>[qw(yes no)],
'yes' =>{
max_in_set=> '1 of yes, no',
},
'no'=>{
max_in_set => '2 of yes, no',
},
comments => {
name => 'Additional Info',
max_len => 3000,
},
};
#
my $vob = CGI::Ex::Validate->new;
open( OUT, ">form2.html" ) or die "can't open out $!";
my $js_uri_path="/CGI-Ex-2.38/lib/CGI/Ex/validate.js";
my $form_name = "the_form"; # name of the form to attach javascript
+ to
my $form = $vob->generate_form(
$val_hash,
{
form_name => $form_name, # will use a random name if not
+ passed
js_uri_path => $js_uri_path,
}
);
print OUT $form;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.