Best Practice creating Forms in WordPress

I was wondering what is the best practice for creating forms in WordPress? As a developer I hesitate to use a plugin like CForms, but I can understand why someone would like to use it. In the end I want to know the following:

  • What is the best practice for creating forms in WordPress? (Custom HTML/CSS with Javascript and PHP validation or just using a specific aspect of the WordPress API?)

Related posts

Leave a Reply

3 comments

  1. I don’t use any part of the WordPress API for forms. You could automatically grab the name and e-mail address out of the cookie WordPress creates when someone leaves a comment, if you want to try to auto-populate some fields.

    An easy way to handle forms is to use Page Templates. That lets you create a new PHP file for a specific page, overriding the default page template of the theme. Then you can simply have the form post to itself and this one page template handles the processing as well.

    http://codex.wordpress.org/Pages#Page_Templates

  2. A lot of what’s available for WordPress in the way of addins, and what gets a lot of attention, is stuff that I find makes little use if you have programming and general web skills. Almost always they seem to (necessarily) overgeneralize a requirement with a zillion options and configuration requirements because they are first of all designed for non- or barely-programmers.

    Just learn the fundamental paradigms, scratch your head and wonder why nothing is consistently abstracted and/or encapsulated, get over it, and use what you already know about php and HTML-based forms. WordPress doesn’t add much in the way of either tools or constraints.

    I find the Widget feature applies usefully to most everything these days, and Forms is a candidate. But that’s my own WordPress viewing prism – YMMV.

  3. What do you mean by “in WordPress”? Do you just mean placing the form HTML in a WordPress template? Or storing data collected in the WordPress DB? If you just want to create a form on your site, there’s nothing WordPress-specific to worry about. I believe there’s some special WordPress data facilities you can use if you’re creating a widget or plugin or whatever they’re called now. But if you’re not, just create the HTML, and point it at a target URL that processes the values and puts them in a DB, WordPress or otherwise. That target URL could be a separate PHP resource, or the same page. If it’s the same page, you just need to include your PHP somewhere in the main WordPress flow.