homepage Welcome to WebmasterWorld Guest from 107.21.187.131
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

    
Can't copy and paste into textarea
Form doesn't like invisable characters.
suzie250




msg:3375355
 3:31 am on Jun 22, 2007 (gmt 0)

The textarea in my form doesn't like some of the invisable characters that some word processing programs insert into documents.

When the form is processed, and a preview is shown, the textarea part is blank (as though nothing was entered into it).

As long as visitors type into this box it's not a problem, but there are times when a copy and paste is so much easier for them.

I've noticed this problem when trying to copy .wps files and another that I cannot remember. (Notepad is never a problem.)

Is there a fix for this or maybe a work around that I can suggest to visitors?

Also, I wasn't sure if a fix is possible if it's php related or just a normal form issue.

Thanks,
Suzie

 

ahmedtheking




msg:3376069
 6:37 pm on Jun 22, 2007 (gmt 0)

Is it a plain text box or a WYSIWYG?

suzie250




msg:3376367
 2:10 am on Jun 23, 2007 (gmt 0)

It's just a plain text box. The preview of the form is echoed with HTMLSpecialChars.

ahmedtheking




msg:3376546
 8:25 am on Jun 23, 2007 (gmt 0)

Is it a browser specific issue or does it fail right across the board?

suzie250




msg:3377322
 2:16 pm on Jun 24, 2007 (gmt 0)

Not a browser problem.

After some more testing, I have it boiled down to the apostrophe, so it's not even a hidden character, as I had thought.

Copying from an email also causes the text to disappear when there is an apostophe in the text.

Apostrophe's are not an issue when text is typed directly into the form.

When I copy something, is the apostrophe being converted to something that my form can't handle?

tedster




msg:3377383
 3:55 pm on Jun 24, 2007 (gmt 0)

While it's true that "a rose is a rose is a rose", the same cannot be said for apostrophes.

Normal keyboard typing usually just creates ASCII characters -- a straight up-and-down apostrophe, for example. But when you copy/paste, you may be copying a character that is not a "true" apostrophe or single quote, but rather an extended character, such as a right-single quote. This is a curly version or "smart" version of an apostrophe -- such as the characters used in word processing applications and typesetting. See this Wikipedia page [en.wikipedia.org] for more.

Depending on what kind of server processing is going on for form input, this extended character may not be well accomomdated.

suzie250




msg:3377494
 6:56 pm on Jun 24, 2007 (gmt 0)

For others looking for solutions, do searches for "smart quotes" or "smart apostrophes". You'll find solutions in one form or another.

Thanks guys for guiding me in the right direction.

lavazza




msg:3377607
 10:01 pm on Jun 24, 2007 (gmt 0)

Do you have a Content-Type meta tag to declare a client-side char-set?

e.g.

<meta http-equiv="Content-Type"  
content="text/html; charset=iso-8859-1">

Sothpaw




msg:3378184
 1:46 pm on Jun 25, 2007 (gmt 0)

i have found a copy paste work-a-round that has helped me a ton when going back and forth between different programs and browsers.

copy from one program.
paste into Notepad (i always keep a shortcut next to my start button)
then highlight all and copy all
then paste into where you want it to go.

give it a shot. this may work for you. if it doesn't I'd like to know so i can keep track of this and find out what does work.

suzie250




msg:3378274
 3:14 pm on Jun 25, 2007 (gmt 0)

lavazza, yes I do have the content-type meta tag set.

Copying into Notepad does not work for me.

It would be a easy alternative if it did, for me, but it's not a good solution for my site's visitors.

I need to keep things as simple as possible for them and asking them to do something before they actually fill out a form is too much.

Besides the extra work for a visitor, I think it would also reflect a poorer quality of the site.

I'll be testing some code to clean the text up as it is submitted through the form.

lavazza




msg:3378540
 7:27 pm on Jun 25, 2007 (gmt 0)

Maybe this will help

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en-GB">
<head>

<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">

<script type="text/javascript">

var myMessage01 ='\nPlease type or paste something into the \'Input\' box\n\n';

function clearFields()
{
document.myFormName.theInput.value='';
document.myFormName.encodedString.value='';
}

function cleanseUserInput(theInputField)
{

var theInput = document.myFormName.theInput.value;
var encodedString = '';

if (theInput == '')
{
alert(myMessage01);
}
else
{
var regLength = theInput.length;
//alert('regLength is ' + regLength);
for (i = 0; i < regLength; i++)

{
//var charCode = '000';
var curChar = (theInput.charAt(i));
if (curChar == '“'){ curChar = '"'; }

if (curChar == '”'){ curChar = '"'; }
if (curChar == '<'){curChar = '&lt;'; }
if (curChar == '>'){curChar = '&gt;'; }
encodedString += curChar;
}

document.myFormName.encodedString.value = encodedString;
}
}
//-->

</script>
<title>convert curly quotes
</title>
</head>

<body onload="clearFields();">

<h1> convert “curly quotes” to "straight quotes"</h1>

<form name="myFormName" id="myFormName" action="#" method="post">

This is some text with 'wrong' characters that you can copy and paste into the 'input box' to test that it works
<br/>
<br/>

&lt; “abcdefg” &gt;
<br/>
<h3> user input </h3>
<textarea name="theInput"
rows="1"
cols="60"
id="theInput"></textarea>

<br/>
<input class="myButtonClass"
type="button"
value="&nbsp; Go &nbsp;"
onclick="cleanseUserInput(theInput);"/>
<br/>
<br/>
<h3> 'cleansed' output </h3>
<textarea name="encodedString"
rows="2"
cols="60"
id="encodedString"></textarea>
<br/>
<input class="myButtonClass"
type="reset"
value=" &nbsp;reset &nbsp;"
onclick="clearFields(theInput, encodedString);"/>

</form>

<noscript>
Javascript must be enabled in your browser
</noscript>

</body>

</html>

[edited by: tedster at 1:45 am (utc) on June 26, 2007]
[edit reason] member request - missing spaces fixed [/edit]

encyclo




msg:3378566
 7:44 pm on Jun 25, 2007 (gmt 0)

You can try adding an
accept-charset attribute on the form element:

<form action="/pat/to/script.php" [b]accept-charset="ISO-8859-1"[/b]>

According to this thread [webmasterworld.com] you should try defining the charset of the page via a HTTP header.

Ideally, using UTF-8 rather than ISO-8859-1 is a better choice, as the "curly quotes" and other characters exist in UTF-8.

Also see the thread: UTF-8, ISO-8859-1, PHP and XHTML [webmasterworld.com]. :)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved