Page 1 of 2
Prevent Continuous characters on a form - can you?
Posted: Mon Apr 18, 2011 3:24 am
by simonmlewis
We keep getting people enter things like this on forms:
[text]!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!![/text]
About three to four times that amount, which stretches out the page.
It's a moderation page, so it's more for our benefit than the users benefit, but is there a way to stop them entering that into a form. Some kind of validation that checks for 'amount of non-stop characters without spaces'?
Thanks.
Re: Prevent Continuous characters on a form - can you?
Posted: Mon Apr 18, 2011 2:08 pm
by pickle
You can set the maximum width of the html element that text appears in. Setting overflow to "hidden" will automatically cut off any text that extends beyond that width. I'm guessing reasonable entries will be no where close to the maximum width.
Re: Prevent Continuous characters on a form - can you?
Posted: Mon Apr 18, 2011 2:18 pm
by simonmlewis
It goes into a <td> not a DIV.
So if I place it into a DIV, and set it to
[text].entry
{
overflow: hidden;
width: 300px;
}[/text]
Would that do it then?
Re: Prevent Continuous characters on a form - can you?
Posted: Mon Apr 18, 2011 2:29 pm
by pickle
You should be able to apply those styles to the <td> itself.
Re: Prevent Continuous characters on a form - can you?
Posted: Mon Apr 18, 2011 2:44 pm
by simonmlewis
<td valign='top' style='width: 240px; overflow-x: hidden;'>
?? This isn't working. It's still stretches.
Wish I could just stop them doing it.
Re: Prevent Continuous characters on a form - can you?
Posted: Mon Apr 18, 2011 2:52 pm
by pickle
overflow-x isn't part of CSS 2.1 I believe. Try just overlow. If that doesn't work - you might need to put it in a <div> like you originally thought.
Re: Prevent Continuous characters on a form - can you?
Posted: Mon Apr 18, 2011 3:00 pm
by simonmlewis
<td valign='top' style='width: 240px; overflow: scroll'>
This fails too.
<div> isn't working either - it just forces the page out.
Re: Prevent Continuous characters on a form - can you?
Posted: Mon Apr 18, 2011 3:03 pm
by pickle
You changed 2 things there: overflow-x > overflow and hidden > scroll.
What do you mean by "forces the page out"?
Re: Prevent Continuous characters on a form - can you?
Posted: Mon Apr 18, 2011 3:09 pm
by simonmlewis
If someone enters "ccccoooooooooooooooooooooooooooooooool" with about 100-200 o's, the width of the cell it is in, forces out - so the overall width of the web site goes from 900px to 'you name it'. It creates a horizontal scroll in the browser itself.
Re: Prevent Continuous characters on a form - can you?
Posted: Mon Apr 18, 2011 3:12 pm
by pickle
I don't know then. Setting the width & overflow on a div should do it.
Re: Prevent Continuous characters on a form - can you?
Posted: Mon Apr 18, 2011 3:17 pm
by simonmlewis
Should be code of: width: 230px; overflow: auto (or scroll), do it in a <td> ?
Re: Prevent Continuous characters on a form - can you?
Posted: Mon Apr 18, 2011 3:25 pm
by pickle
Not "auto", "hidden". It doesn't work on a <td> (I was evidently wrong), but it definitely should work in a <div>.
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
<table border="1">
<tr>
<td>
<div style = "width:300px;overflow:hidden;">
this is really long text that should be broken up & work just fine
</div>
</td>
</tr>
<tr>
<td>
<div style = "width:300px;overflow:hidden;">
cooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooool
</div>
</td>
</tr>
<tr>
<td style = "width:300px;overflow:hidden;">
cooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooool
</td>
</tr>
</table>
</body>
</html>
Re: Prevent Continuous characters on a form - can you?
Posted: Mon Apr 18, 2011 3:58 pm
by simonmlewis
Ahh ok. No what happens with that style, is that the text disappears off the page, so if something were to enter a load of 'gumf', then half of it wouldn't be seen.
So I either need a way of seeing when they enter their gumf, of saying "sorry, too much incorrect text", or, wrapping it - but how to do you wrap continuous text? That css just doesn't do it.
Re: Prevent Continuous characters on a form - can you?
Posted: Mon Apr 18, 2011 4:02 pm
by pickle
You can't wrap continuous text as far as I know. You can do 2 things (ideally you should do both actually):
1) Set a "max" value on the textfield so users can only enter X number of characters.
2) Do a simple strlen() call on the POSTed value to check the length.
Re: Prevent Continuous characters on a form - can you?
Posted: Mon Apr 18, 2011 4:06 pm
by simonmlewis
Thing is, there is a big difference between entering:
"this is soooooooooooooooooooooooooooooooooo (with hundreds of o's) coooool."
And entering "I love this product, bl bla bla lba this is fabulous (and lots of other nice words)."
I cannot restrict how many characters they enter, as it's a kind of Review place, but I wanna stop the continuous characters.
I just don't see it it can be done. surely they do it on THIS web site ???