We’re crazy about blogging!

Smart, my ass

16th October 2006 | Comments (0)

Microsoft Word's 'smart' quotes can wreak havoc with database driven content management systems. We report on yet another Internet Explorer 6 bug.

Just when I thought that IE6 had run out of new bugs with which to torment me, out scuttles a new one. The latest glitch is thankfully rare but that only serves to make it harder to pinpoint and solve. It only rears its ugly head when (1) you are using a multipart form to upload both data and file contents to a server (2) a user has pasted a Microsoft smart quote apostrophe from, say Microsoft Word, into one of the form fields and (3) the user is using IE6. What happens is that IE6 will inexplicable fail to post data from the first field of the form to the server.

<form enctype="multipart/form-data" method="post" accept="jpg, jpeg" action="addentry.php">
<input type="hidden" name="new_data" value="1"></input>
<p>1. Headline</p>
<input type="text" name="headline" size="49"></input>
<p>2. Body text.</p>
<textarea name="bodytext" rows="6" cols="50"></textarea>
<p>3. Image</p>
<input name="image1" type="file"></input>
<input type="submit" value="Add story to database"></input>
</form>

For example, if you were using the above form, the first field variable - new_data - would not be passed to the server. Interestingly, the rest of the form variables - headline and bodytext - and the image1 file data would be posted to the server as normal.

Failure to send the first variable can obviously cause major problems to a web application. In my case, I was using the first variable - new_data - to detect whether new data had been posted before adding the data to a MySQL database using PHP. Everything worked fine when users typed directly into the forms but things went awry when smart quote apostrophes were pasted into the forms from Microsoft Word. Then, the new_data variable was not posted and the PHP script therefore assumed that no new data had been submitted and simply displayed the original empty form again. Users of the site would have spent time filling out the form, only to be presented with an empty form again once they pressed the submit button. They would have every justification for being pissed off and never returning to the site.

Now, I could have asked users not to paste text from MS Word, banishing the possibility of a smart quote apostrophe being submitted. But that would not have been very user friendly, given the popularity of MS Word.

I therefore trawled the web in search of a solution to the problem. After many hours of frustrated searching, I concluded that there was no solution. However, there is a ridiculously simple workaround. Simply add a dummy variable in a hidden field at the start of the form - see below. Then, it will be the useless dummy variable that won?t be passed to the server, rather the useful new_data variable. Problem solved!

<form enctype="multipart/form-data" method="post" accept="jpg, jpeg" action="addentry.php">
<input type="hidden" name="dummy" value="whatever"></input>
<input type="hidden" name="new_data" value="1"></input>
<p>1. Headline</p>
<input type="text" name="headline" size="49"></input>
<p>2. Body text.</p>
<textarea name="bodytext" rows="6" cols="50"></textarea>
<p>3. Image</p>
<input name="image1" type="file"></input>
<input type="submit" value="Add story to database"></input>
</form>

WHAT ARE SMART QUOTES

Microsoft Word automatically changes straight quotation marks ( ' or " ) to curly smart or typographer's quotes as you type. Unfortunately, these smart quotes are not so smart - they can cause web applications to malfunction and often cause ugly characters to appear on web pages.

How to turn off smart quotes in MS Word:

1. On the Tools menu, click AutoCorrect Options, then click the AutoFormat As You Type tab.

2. Under Replace as you type, select or clear the "Straight quotes" with "smart quotes" check box.

Services

Web standards templates

We use CSS and X/HTML to create beautiful standards-compliant templates that can easily be updated site-wide using style sheets.

Ajax and Web 2.0

Advanced websites need advanced technology. Webalon uses Ajax to create responsive and intuitive Web 2.0 applications.

Mapping solutions

With the launch of Google Maps API, Webalon is able to offer its clients sophisticated mapping solutions customised to their needs.

Content management

Our content management systems allow clients to update their sites by filling in forms and clicking buttons.

Databases

Webalon is an expert at creating database-driven websites using the open source PHP and MySQL.

Special effects

Webalon can spice up your website with special effects such as scroll-downs, movement and fade-in/fade outs using its own library of Javascript and DOM scripts.

Copy writing

We can even write content for your website. Webalon employs a journalist who can turn your ideas into punchy copy for your website.