After finding myself writing the same form handling code over and over and over (and over) again, I finally decided to do something about it.
And then FormCorral was born.

Our goal was to provide an interface that defines a list of fields to capture, what to show if an error occurred (such as a required field), and a set of validation rules, since nothing else seems to provide them in a sane fashion.
Also, since FormAPI will be undergoing changes in the coming months (you got it.. I'm on to you :)), I wanted something that wasn't exclusively bound to the structure that FormAPI currently exhibits in Drupal 5.1. This way I can extend its functionality to dynamically generate forms once Drupal 6 is released.
The functionality is pretty basic.. You define a name for the form, a list of fields that the form should capture (with or without validation), and optionally a list of email addresses to send the output of the form to once it's submitted.
The module also has the ability to override the format of those outbound emails if you have custom formatting that needs to be done. This is handled by way of a set of php files based on the list ID in the 'mailtemplate' folder.
A note to all you module purists: yes, this should go in the theme or in the sites folder.. We're aware, and we're trying to find a workable compromise.
Once a form is submitted, it goes into the database as well as (optionally) getting mailed out, so you can get a list of all submissions at any point:

Hooking the form in is very simple. In your module where you define your formapi hooks for _validate and _submit:
function mymodule_form_validate($form_id, $form_values) {
$lid = variable_get("mymodule_form_lid", 0);
if (!$lid) {
$list = whlist_get_list(array("name" => "My Module Form"));
$lid = $list['lid'];
variable_set("mymodule_form_lid", $lid);
}
$form_values['lid'] = $lid;
whlist_validate_form($form_id, $form_values);
}
function mymodule_form_validate($form_id, $form_values) {
$lid = variable_get("mymodule_form_lid", 0);
if (!$lid) {
$list = whlist_get_list(array("name" => "My Module Form"));
$lid = $list['lid'];
variable_set("mymodule_form_lid", $lid);
}
$form_values['lid'] = $lid;
whlist_save_submission($form_values);
return "myform/thanks";
}
Ideally, there are simpler ways to define this data; perhaps by passing this into the form array itself, possibly by grabbing the $form_id itself and storing that in FormCorral.. I'm always open to suggestions.
aaron's blog
Comments
Why not use and further
Why not use and further develop the webform.module? It already handles capture, csv download, display of stats, validation, a form builder and more.
It could use some love from you guys.
A laudable request
Looks like it might be a great match! I'll contact ullgren and see what we can do to help.
Multiforms
Your module looks nice and lightweight... good for creating forms to deploy from other modules.
For other use cases you might want to check out Multiforms which I wrote with the intention of creating a user-friendly form creator for contests and surveys (http://drupal.org/project/multiforms). It has multi-page support, hooks for defining field types, the ability to save groups of fields you frequently reuse, email referrals, and very soon a web interface for adding options to "multiple choice" fields (I'm just testing this now and will deploy to CVS shortly).
Post new comment