We are finding people are jsut tapping space bar and hitting the Submit button.
It's therefore not NULL, but does that mean it is "empty"?
How do I validate in PHP against spaces?
How do I stop someone posted spaces in a form?
Moderator: General Moderators
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
How do I stop someone posted spaces in a form?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do I stop someone posted spaces in a form?
preg_replace spaces and check that length is still > 0? That does nothing to address the larger problem, though. Why are your users doing that?
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do I stop someone posted spaces in a form?
What's the different between that, and empty(trim($var)) ??
People are possibly clicking reply twice, as the page turns over so quickly.
At first, this was caused by people replying, and my not doing validation.
And because I don't think you can validate a <textarea> onsubmit, to ensure something is entered, they went thru blank.
I added a script to stop them if they are "empty", but spaces got thru. So I think TRIM works. As effectly as your version..... any ideas?
How do I check length?
People are possibly clicking reply twice, as the page turns over so quickly.
At first, this was caused by people replying, and my not doing validation.
And because I don't think you can validate a <textarea> onsubmit, to ensure something is entered, they went thru blank.
I added a script to stop them if they are "empty", but spaces got thru. So I think TRIM works. As effectly as your version..... any ideas?
How do I check length?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do I stop someone posted spaces in a form?
Not to worry, this one is very cool:
Code: Select all
http://stanislav.it/javascript-display-content-with-delay/Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do I stop someone posted spaces in a form?
The TRIM doesn't work.
I get this error in my logs:
Am I writing it wrong??
I get this error in my logs:
Line 171 is that line:[Tue Jun 03 09:31:41 2014] [warn] [client 92.14.61.124] mod_fcgid: stderr: PHP Fatal error: Can't use function return value in write context in /var/www/vhosts/site.com/httpdocs/includes/ticket.inc on line 171, referer: http://www.site.com/tickets
Code: Select all
if (empty(trim($message)))
{
}Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do I stop someone posted spaces in a form?
Yes, you have to assign it to a variable before passing it to empty()
Code: Select all
$message = trim($message);
if (empty($message)) {
... etc