One of the things I hate doing is creating forms. Sadly, most webapps use them pretty heavily so not doing them isn’t really an option. What I can do is create a plug-in for Coda to do all the heavy lifting for me. Without further foreshadowing, I give you…the Form Maker Plug-in for Coda.
Installation Instructions
To get the full effect you will need to download several components. First and foremost, you will need the Form Maker plug-in. This is the main plug-in file and will do all the heavy lifting of creating your form elements. There is also a small clipping group that I use for opening and ending the form tags and starting fieldsets. Why didn’t I include this in the plug-in? Because there are many times that I am working on an existing form and need to add a new field. Having the plug-in create an entire new form isn’t as useful as the ability to create elements quickly. And finally, there is a CSS file that handles some very basic formatting to get the form working okay. You can customize this to your heart’s content, but this helps get things laid out so you don’t have to recreate everything. It also declares a few classes that you can assign to the form to change the lay-out quickly (I’ll explain more later). You’re welcome.
Download and unzip the file and then put the Form Maker.codaplugin file in your ~/Library/Application Suport/Coda/Plug-ins folder. Open Coda and you will see the Form Maker option in the Plug-ins Menu. While you have Coda open, open the Clips panel and import the clips into it. I’ll outline these further in the instructions. The CSS file you can store wherever you wish. but keep it handy for including in your projects.
Usage Instructions
So now you are ready to make a form. Open up your HTML document and make sure you include the forms.css file in the <head>. Now go and type form and hit the tab key. You have now started your form with a new fieldset and legend. Your cursor is in the <legend> tag so you can name it whatever you like. You can end your form by typing /form and hitting the tab key. This will insert a submit button and close the form nicely.
Your form should look something like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Form Maker Plug-in Tutorial</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<link href="forms.css" media="screen" rel="stylesheet" type="text/css" />
</head>
<body>
<form action="" class="form">
<fieldset>
<legend><span>Text Fields</span></legend>
</fieldset>
<dl>
<dt><label> </label></dt>
<dd><input class="button" type="submit" name="" value="Submit" id="submit" /></dd>
</dl>
</fieldset>
</form>
</body>
</html>
Now comes the fun part. Start typing the labels of the fields you will need. The only real caveat is that you need to start with no leading tabs. So it will look something like this:
<form action="" class="form">
<fieldset>
<legend><span>Text Fields</span></legend>
First Name
Last Name
</fieldset>
<dl>
<dt><label> </label></dt>
<dd><input class="button" type="submit" name="" value="Submit" id="submit" /></dd>
</dl>
</fieldset>
</form>
So let’s take a look at the different types of elements and the options the Form Maker plug-in has for them.
Text Fields & Textareas
These are pretty basic. Type in the label name, select it and hit ⌃T to create text fields or hit ⌃A to create Textareas. The only option is whether or not the filed is required. If it is, add an asterisk to the front like this:
First Name
*Last Name
Select Fields
These require a label on the first line and the contents are below preceded by a tab. Select the whole batch and hit ⌃S. These are the special options for <select>s Including an asterisk on the first line marks it as a required field. An asterisk on a content line makes that one selected by default. You can create <optgroup>s by preceding the title with a hyphen. Here’s an example:
*Select Label
-Optgroup 1
Option 1
Option 2
*Option 3
-Optgroup 2
Option 1
Option 2
Option 3
Another Label
Option 1
Option 2
Option 3
Radio Buttons & Checkboxes
These are formatted somewhat similarly to <select>s with a label and then tabbed options underneath. Again, an asterisk on the label will make it required and an asterisk on an option makes it checked. Select the block and hit ⌃R for radio buttons and ⌃C for checkboxes. Type it out as follows:
*Radio Buttons
Yes
No
*Maybe
Checkboxes
Option 1
Option 2
Option 3
The Magic Stylesheet
So here’s why you care about the included stylesheet. with the change of a class you can alter the layout and flow of the form. The default is class=“form” which produces a vertical flowing layout with the label right-aligned and next to the input field.
Changing it to class=“form-h1” makes it flow horizontally with the labels above the input fields. class=“form-h2” is also horizontal but the labels are now next to the input fields.
If you like the vertical flow then class=“form-v1” is a vertical flow with the labels above the input fields. class=“form-v2” is like the default layout except the labels are left-aligned.
So a simple class change will totally alter the layout without any effort on your part.
About the Markup
Astute observers will note that the markup is not exactly what you would expect. Each element is wrapped in a <dl> with the <label> inside the <dt> and the <input> inside the <dd>. This method of marking up form elements was not mine. It is the system we use for creating forms here at work. I happen to like it and I wrote the plug-in to help at work so I am releasing it as is. If you have a different method of marking up your forms and know a little PHP you can easily modify the plug-in scripts to mark it up as you like. Just download the Coda Plug-in Creator and open the plug-in.