Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Disabling paste into a form control?

Disabling paste into a form control?
Thread Tools
Clinically Insane
Join Date: Nov 1999
Status: Offline
Reply With Quote
Aug 21, 2003, 12:54 PM
 
I'm building a site with a set of forms. However, I have an interesting problem: I need to ensure that the user cannot paste into one of the fields. Copying out of the field isn't a problem, and the user still needs to be able to enter text, but I need to disable pasting if at all possible (the user needs to actually type out a short phrase, and we do not want a user to be able to just paste it in).

Any ideas? Can I use JavaScript to do this? Am I going to have to resort to Flash?
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
     
Dedicated MacNNer
Join Date: Aug 2002
Status: Offline
Reply With Quote
Aug 21, 2003, 07:59 PM
 
The simplest solution would be to make that 'short phrase' a graphic so the user can't copy it in the first place.

--will
     
Senior User
Join Date: May 2001
Location: Nottingham, UK
Status: Offline
Reply With Quote
Aug 22, 2003, 05:09 AM
 
I thought about having the short phrase in a disabled text field:

http://80.234.160.78/tests/disabled.asp

however, you can still copy the text in it with IE on the PC

Are you doing this to stop automated registrations?

I think Flash, or using the PHP gif generator would be required here
     
Dedicated MacNNer
Join Date: Aug 2002
Status: Offline
Reply With Quote
Aug 22, 2003, 09:50 AM
 
one thing that may work (i haven't tried this) would be to put a transparent gif above the the text (on a higher layer). Hopefully this would mean that the user would not be able to select the text because of the gif.

--will
     
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Aug 22, 2003, 11:39 AM
 
Originally posted by clam2000:
one thing that may work (i haven't tried this) would be to put a transparent gif above the the text (on a higher layer). Hopefully this would mean that the user would not be able to select the text because of the gif.

--will
I think that the position of the text field would be too hard to find. I supose you could fix the size and use position: relative and all that but I don't know how well it'd work. On a similar note, I did something like this where the header of a site simply loaded over a free counter
     
Senior User
Join Date: Dec 2002
Status: Offline
Reply With Quote
Aug 23, 2003, 02:31 PM
 
What type of phrase is this going to be? letter and number combo? I think images would be your best bet.
Travis Sanderson
     
Forum Regular
Join Date: Nov 2000
Location: Oslo, Norway
Status: Offline
Reply With Quote
Aug 25, 2003, 08:19 PM
 
Ok, I see tho solutions.

a)
- Check the event (onKeyUp) to see if the ctrl key (WinDOS) or command Key (Mac) was pressed.

- Clear the textfield

b)
- Check the event (onKeyUp) to see if the length of the string in the textfield was increased with more than one.
- If true, clear the textfield
- If false do nothing

I'll be back...
     
Forum Regular
Join Date: Nov 2000
Location: Oslo, Norway
Status: Offline
Reply With Quote
Aug 25, 2003, 09:20 PM
 
Well.. This was a bit more complicated than I thought.

It seems that the browser (Safari) does not generate a key event when the "Apple key" is pressed.

This script might work on Windows. (I don't have any ten-foot-poles at hand, so I cannot test it).
Since those people use the ctrl key, as far as I know.

I will look into it further.

Code:
<html> <head> <script type="text/javascript" language="Javascript"> <!-- var lastLength = 0; function handlePaste(textField) { if((textField.value.length - lastLength) > 1) { textField.value = ''; // Clear the textfield lastLength = 0; // Reset character counter alert("You tried to paste, you bastard"); } lastLength = textField.value.length; } //--> </script> </head> <body> <form name="myform" method="post"> <input type="text" name="foo" onKeyUp="handlePaste(this);"> </form> </body> </html>
     
Dedicated MacNNer
Join Date: Aug 2002
Location: Chicago
Status: Offline
Reply With Quote
Aug 26, 2003, 09:18 AM
 
Try this site this script will disable a field in a form but still show the text.

JavaScript Section has great information on Javascript.



|
|
     
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Aug 27, 2003, 08:56 AM
 


< input name="test" value="test" readonly="readonly" />
Computer thez nohhh...
     
Mac Elite
Join Date: Aug 2001
Location: Capitol City
Status: Offline
Reply With Quote
Aug 28, 2003, 09:06 PM
 
Originally posted by Simon Mundy:


< input name="test" value="test" readonly="readonly" />
You'd still be able to copy from that, wouldn't you? I'm too lazy to try it out.

I like the checking for keystrokes idea.

You might rather count the keystrokes made in the text area, vs. how many are present when you either unfocus, or submit the form. It seemed like there could be a potential problem with a modifier/key combination with onKeyUp.
     
Clinically Insane
Join Date: Nov 1999
Status: Offline
Reply With Quote
Aug 28, 2003, 09:08 PM
 
Originally posted by DeathMan:
You'd still be able to copy from that, wouldn't you? I'm too lazy to try it out.
Oh, I don't mind if people can copy out. I just need to be sure they can't paste in. The phrase is just something short and generic; "I Agree" would be a good example. I just want to make sure that it is actually typed out, rather than simply pasted in.
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
     
1c3
Forum Regular
Join Date: May 2003
Location: Jämtland - Sweden
Status: Offline
Reply With Quote
Sep 4, 2003, 03:34 PM
 
wouldn't it be possible to with a JavaScript controll if more than one character is added at one time?

Like if you one by one it is fine, but if there is 5 at once the field is cleared.

I don't know if it is possible, it was just an idea that went running through my head^^
Mighty3k @ #MacNN
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:19 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2