Prevent Continuous characters on a form - can you?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Prevent Continuous characters on a form - can you?

Post 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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Prevent Continuous characters on a form - can you?

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Prevent Continuous characters on a form - can you?

Post 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?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Prevent Continuous characters on a form - can you?

Post by pickle »

You should be able to apply those styles to the <td> itself.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Prevent Continuous characters on a form - can you?

Post 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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Prevent Continuous characters on a form - can you?

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Prevent Continuous characters on a form - can you?

Post by simonmlewis »

<td valign='top' style='width: 240px; overflow: scroll'>

This fails too.
<div> isn't working either - it just forces the page out.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Prevent Continuous characters on a form - can you?

Post by pickle »

You changed 2 things there: overflow-x > overflow and hidden > scroll.

What do you mean by "forces the page out"?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Prevent Continuous characters on a form - can you?

Post 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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Prevent Continuous characters on a form - can you?

Post by pickle »

I don't know then. Setting the width & overflow on a div should do it.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Prevent Continuous characters on a form - can you?

Post by simonmlewis »

Should be code of: width: 230px; overflow: auto (or scroll), do it in a <td> ?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Prevent Continuous characters on a form - can you?

Post 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>
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Prevent Continuous characters on a form - can you?

Post 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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Prevent Continuous characters on a form - can you?

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Prevent Continuous characters on a form - can you?

Post 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 ???
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply