views:

64

answers:

3

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?)
A: 

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.

gWiz
Thanks for the input. This is exactly what I was wondering. Ive done some wordpress and Ive done the HTML/CSS and JS/PHP validation myself but I was wondering if the community does anything else like use some sort of Wordpress API besides the plugin CForms. I appreciate your help.
alvincrespo
You're welcome!
gWiz
+1  A: 

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

Dan Grossman
+2  A: 

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.

le dorfier