Perl Form Builder ::Features ::Download ::Tutorial ::Examples
::Documentation ::FormBuilder Google Group ::Old List Archives ::Contribute
Note: The mailing list is has been replaced by the Google FormBuilder Group


1. Intro to FormBuilder
2. A Simple Form
3. Form Method
4. Input Validation
5. Field Options
6. Multi-Select Lists
7. Field Data
8. Field Attributes
9. HTML Formatting
10. Custom Headers
S. Summary


1. Trickier Forms
2. Perl References
3. Default Values
4. CGI Stickiness
5. JavaScript Actions
6. Input Validation 2
7. Multiple Submits
8. JavaScript Actions 2
9. Modules & mod_perl
10. Smartness
S. Summary


1. Remaining Features
2. Intro to Templates
3. HTML::Template
4. HTML::Template 2
5. Template Toolkit
6. Exploiting render()
7. Multi-Screen Apps
8. Multi-Screen Apps 2
9. Multi-Screen Apps 3
10. Custom Messages
S. Summary

Intermediate Tutorial - Step 5: JavaScript Actions Print

<< CGI Stickiness | Input Validation 2 >>

As you've already seen, FormBuilder actually generates tons of JavaScript for you, for the purpose of client-side form validation. JavaScript has other uses too, such as causing events to happen when a field is modified.

If you recall, back when we were talking about field attributes, we mentioned that any options not recognized by FormBuilder would be passed through to your HTML tag. So, one could set a JavaScript action like so:

$form->field(name     => 'search',
             onchange => 'this.form.submit()');
This will work just fine. But there's actually an even better way to do it.

Have you ever been annoyed at how the different input fields have different event handlers? Some are onclick, others are onchange, and so forth. This isn't the best for code maintenance, since this means you have to change your JavaScript actions if you update your options.

Instead, FormBuilder provides an option called jsclick. This is specified to field(), just like above, with the advantage that FormBuilder will automatically translate it to the correct action depending on the type of field:

$form->field(name    => 'search',
             jsclick => 'this.form.submit()');
This translates to less code maintenance in the long-run, plus it eliminates silly errors (such as using onchange for a checkbox).

It is also possible to specify special form actions, equivalent to onsubmit but more robust, which are covered just a little later.

<< CGI Stickiness | Input Validation 2 >>

FormBuilder is © Nate Wiger, with contributions from many people.