Posts Tagged ‘Webform TinyMCE’

Duplicate results in Webform module Analysis display

Colin Calnan | Tuesday, June 9th, 2009

I came across a problem with the Webform module recently that seemed initially puzzling but on closer examination was actually quite simple.

The Problem

When viewing the webform results in the analysis page it appeared that there were duplicate values for some fields:

webform-analysis-duplicates

The Cause

TinyMCE. It seems that the webform and it’s components may have been created when TinyMCE was disabled and then edited at a later date when it was enabled. The visibility settings for TinyMCE were as follows:

node/*
user/*
comment/*
admin/build/block/*

This meant that TinyMCE was being attached to textareas in the webform component editing pages, usually at ‘node/xx/edit/components/x’.

“select” form components in webforms use a textarea to allow you to input the options for the select field. Each option value is input on a new line in the textarea. With TinyMCE enabled the options had a <br /> tag appended to them. Whenever the site editor edited the form component values, and had TinyMCE enabled, the value of the option changed from “College” to “College<br />”. So any further submissions to the form resulted in the submitted data being recorded as “College<br />”

When running analysis on this data, the results showed up as duplicates

College 34
College 215

due to the <br /> being rendered out in the HTML, it really should have read

College<br /> 34
College 215

The Solution

Turn off TinyMCE for all webform component editing pages. I did this via the Visibility setting in TinyMCE module:

node/add/*
node/*/edit
user/*
comment/*
admin/build/block/*

Now it only shows up on editing nodes and add nodes, not editing form components.

Now for the data. The first thing to do was to sort out the webform component. I tried to run a find and replace on the database in the ‘webform_components’ table, but this didn’t work, so I resorted to editing and re-saving each form component individually. Then I moved to cleaning up the submitted data. I ran a simple find and replace query on this to remove the unwanted <br /> tags:

UPDATE `webform_submitted_data` set `data` = replace(`data`,'&lt;br /&gt;','') WHERE `nid` = NODE_ID_HERE;

This says; Update my webform_submitted_data table by replacing all instances of <br /> in the data table, with nothing, and do this for all data submitted for the webform whose nid(Node ID) is the id of the webform with the funky data.

This worked a treat and the values reset themselves nicely:

webform-analysis-duplicates-2

 


t. 604.684.2498 | f. 604.721.4007 | e. turningheads [at] raisedeyebrow.com