Date: Saturday February 8, 2003 @ 18:00
Author: matt
Update of /home/cvs/AxKit-XSP-PerForm
In directory ted.sergeant.org:/home/matt/Perl/AxKit-XSP-PerForm
Modified Files:
PerForm.pm
Log Message:
Document new attributes
Also make submit and cancel buttons use ->can()
Add onsubmit and oncancel attribute support
Log:
PR:
Index: PerForm.pm
===================================================================
RCS file: /home/cvs/AxKit-XSP-PerForm/PerForm.pm,v
retrieving revision 1.14
retrieving revision 1.15
diff -b -u -r1.14 -r1.15
--- PerForm.pm 2003/02/08 15:46:13 1.14
+++ PerForm.pm 2003/02/08 18:00:25 1.15
@@ -1,4 +1,4 @@
-# $Id: PerForm.pm,v 1.14 2003/02/08 15:46:13 matt Exp $
+# $Id: PerForm.pm,v 1.15 2003/02/08 18:00:25 matt Exp $
package AxKit::XSP::PerForm;
@@ -16,8 +16,8 @@
@EXPORT_TAGLIB = (
'textfield($name;$default,$width,$maxlength,$index,$onvalidate,$onload)',
'password($name;$default,$width,$maxlength,$index,$onvalidate,$onload)',
-
'submit($name;$value,$image,$alt,$border,$align,$goto,$index,$onvalidate,$onload)',
-
'cancel($name;$value,$image,$alt,$border,$align,$goto,$index,$onvalidate,$onload)',
+ 'submit($name;$value,$image,$alt,$border,$align,$goto,$index,$onsubmit)',
+ 'cancel($name;$value,$image,$alt,$border,$align,$goto,$index,$oncancel)',
'checkbox($name;$value,$checked,$label,$index,$onvalidate,$onload)',
'file_upload($name;$value,$accept,$onvalidate,$onload)',
'hidden($name;$value,$index,$onload)',
@@ -96,17 +96,31 @@
};
my $name;
+ my $onsubmit;
+ my $oncancel;
+ my $onformend;
for my $attr (@{$element->{Attributes}}) {
if ($attr->{Name} eq 'name') {
$name = $attr->{Value};
}
+ elsif ($attr->{Name} eq 'onformend') {
+ $onformend = $attr->{Value};
+ }
+ elsif ($attr->{Name} eq 'onsubmit') {
+ $onsubmit = $attr->{Value};
+ }
+ elsif ($attr->{Name} eq 'oncancel') {
+ $oncancel = $attr->{Value};
+ }
}
$e->end_element($form_el);
return <<EOT;
-end_form_${name}(\$_form_ctxt, \$cgi->param('__submitting'))
- if defined \&end_form_${name};
+my (\$package) = caller;
+if (my \$sub = \$package->can('$onformend' || 'end_form_$name')) {
+ \$sub->(\$_form_ctxt, \$cgi->param('__submitting'));
+}
#warn("submitting? ".(\$cgi->param('__submitting')?"yes":"no").", failed?
".(\$_form_ctxt->{_Failed}?"yes":"no"));
@@ -116,8 +130,9 @@
no strict 'refs';
my \$redirect;
\$redirect = \$_cancel_goto{\$cancel};
- \$redirect = "cancel_\$_cancel_index{\$cancel}{'name'}"->(\$_form_ctxt,
\$_cancel_index{\$cancel}{'index'})
- if defined \&{"cancel_\$_cancel_index{\$cancel}{'name'}"};
+ if (my \$sub = \$package->can(\$_cancel_index{\$cancel}{oncancel} ||
+'$oncancel' || "cancel_\$_cancel_index{\$cancel}{name}")) {
+ \$redirect = \$sub->(\$_form_ctxt,
+\$_cancel_index{\$cancel}{'index'});
+ }
if (\$redirect) {
AxKit::XSP::WebUtils::redirect(\$redirect);
}
@@ -131,8 +146,9 @@
no strict 'refs';
my \$redirect;
\$redirect = \$_submit_goto{\$submit};
- \$redirect = "submit_\$_submit_index{\$submit}{'name'}"->(\$_form_ctxt,
\$_submit_index{\$submit}{'index'})
- if defined \&{"submit_\$_submit_index{\$submit}{'name'}"};
+ if (my \$sub = \$package->can(\$_submit_index{\$submit}{onsubmit} ||
+'$onsubmit' || "submit_\$_submit_index{\$submit}{name}")) {
+ \$redirect = \$sub->(\$_form_ctxt,
+\$_submit_index{\$submit}{'index'});
+ }
if (\$redirect) {
AxKit::XSP::WebUtils::redirect(\$redirect);
}
@@ -192,8 +208,8 @@
};
}
-sub submit ($;$$$$$$$) {
- my ($name, $value, $image, $alt, $border, $align, $goto, $index) = @_;
+sub submit ($;$$$$$$$$) {
+ my ($name, $value, $image, $alt, $border, $align, $goto, $index, $onsubmit) = @_;
my ($package) = caller;
no strict 'refs';
@@ -205,6 +221,7 @@
${"${package}::_submit_goto"}{$name.$index} = $goto if $goto;
${"${package}::_submit_index"}{$name.$index}{'index'} = $index;
${"${package}::_submit_index"}{$name.$index}{'name'} = $name;
+ ${"${package}::_submit_index"}{$name.$index}{'onsubmit'} = $onsubmit;
# save
if ($image) {
@@ -231,8 +248,8 @@
}
}
-sub cancel ($;$$$$$$$) {
- my ($name, $value, $image, $alt, $border, $align, $goto, $index) = @_;
+sub cancel ($;$$$$$$$$) {
+ my ($name, $value, $image, $alt, $border, $align, $goto, $index, $oncancel) = @_;
my ($package) = caller;
no strict 'refs';
@@ -244,6 +261,7 @@
${"${package}::_cancel_goto"}{$name.$index} = $goto if $goto;
${"${package}::_cancel_index"}{$name.$index}{'index'} = $index;
${"${package}::_cancel_index"}{$name.$index}{'name'} = $name;
+ ${"${package}::_cancel_index"}{$name.$index}{'oncancel'} = $oncancel;
# save
if ($image) {
@@ -694,9 +712,10 @@
callbacks you recieve a C<$ctxt> object. This is simply an empty hash-ref that
you can use in the callbacks to maintain state. Actually "empty" is an
exhageration - it contains two entries always: C<Form> and C<Apache>. "Form" is
-a simply a hashref of the entries in the form. So for example, the firstname
+a simply a hashref of the entries in the form (actually it is an Apache::Table
+object, which allows for supporting multi-valued parameters). So for example, the
+firstname
below is in C<$ctxt->{Form}{firstname}>. "Apache" is the C<$r> apache request
-object for the current request.
+object for the current request, which is useful for access to the URI or headers.
sub validate_firstname {
my ($ctxt, $value) = @_;
@@ -818,6 +837,24 @@
that handles the purchase of the associated item.
NOTE: arrays not supported for file-upload elements.
+
+=head1 XSP INHERITANCE
+
+Starting with AxKit 1.6.1 it is possible to specify a class which your XSP page
+inherits
+from. All the validate, load, submit and cancel functions can be in the class you
+inherit from, reducing code duplication, memory usage, and complexity.
+
+=head1 SPECIFYING CALLBACKS
+
+All of the documentation here uses the default callbacks which are implied by the name
+of the form element you give. Unfortunately this makes it difficult to have multiple
+elements with the same validation logic without duplicating code. In order to get
+around
+this you can manually specify the callbacks to use.
+
+Every main tag supports both C<onvalidate> and C<onload> attributes which specify perl
+function names to validate and load respectively. Submit buttons support C<onsubmit>
+attributes. Cancel buttons support C<oncancel> attributes. Forms themselves support
+both C<oncancel> and C<onsubmit> attributes.
=head1 TAG DOCUMENTATION
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]