Accessing cforms Data Directly

I’m using the cforms plugin on one site at the client’s request, and I needed to access some of the form’s data. Their API didn’t have what I needed, so I thought I’d just query the database directly. But when I looked at the database I didn’t see any tables for it. I thought that was kind of odd, but figured maybe they just used a bunch of wp_options fields, but I didn’t notice anything when I skimmed through the table. Then I thought maybe they were writing out to an XML file, so I looked through the file system, but found nothing. Kind of frustrated, I started skimming through the code to try and figure out where hell it was storing it’s data. I Didn’t find anything solid, so I searched their forums and on Google, and found nothing.

I came back a few days later and skimmed through the code again and eventually figured out that it was using the wp_options table, but only one field. All of the global settings, form settings and form data are stored in a single field, in a serialized format that only an MIT grad on crack could parse by hand.

I added a post to their forums to help anyone else in my position, and also to mention that maybe their approach wasn’t the most intuitive, organized or standard. After a couple of days I checked back to see if anyone had left any comments on it, but it was gone. Lame… How petty and insecure do you have to be to censor criticism?

So anyway, in the end all you really need to do is use get_option() to get an associative array of all of the data.

$cforms = get_option('cforms_settings'); // get the data
echo '<pre>'. print_r($cforms, true) .'</pre>'; // output in readable format


Update:
Ok, so this is really more a case of me being behind the curve on WP plugin development. Using serialized options is the standard now.

6 thoughts on “Accessing cforms Data Directly

  1. Thanks for posting this. I’ve been using cforms on a particular project and, well, I freaked out when I saw how they stored the form data. Why, oh why wouldn’t they want to use a separate table with each row, perhaps, having the form-specific data? It seems like storing it as a gigantic serialized string is just asking for trouble.

  2. Do I have to be within the WordPress environment to do this? I am trying to access specific cforms data from a page outside of WordPress so that I can eliminate all of the excess and then print out a formated table.

  3. Hey Kyle, I think you could do that. Try this:

    1) mysql_connect() to the WordPress database (using the database user, name, password from /config.php)
    2) $rawCForms = mysql_fetch_assoc(mysql_query(“SELECT option_value FROM wp_options WHERE option_name = ‘cforms_settings'”));
    3) $arrayCForms = unserialize($rawCForms);

  4. I am new in cform plugin.
    Please explain completely how can we get data from cform plugin and how to insert it into mysql database thand how to retrieve this data from databse as well. I am working on a project i need it urgently please reply as soon as possible. Thanks

  5. Where can I put the page that uses the get_entries() function? I want to use it as part of CRON job. I realize it must include certain libraries from the plugin. But which ones<

Leave a Reply

Your email address will not be published. Required fields are marked *