Page 1 of 1

How do I stop someone posted spaces in a form?

Posted: Mon Jun 02, 2014 12:36 pm
by simonmlewis
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?

Re: How do I stop someone posted spaces in a form?

Posted: Mon Jun 02, 2014 1:16 pm
by Celauran
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?

Re: How do I stop someone posted spaces in a form?

Posted: Mon Jun 02, 2014 1:32 pm
by simonmlewis
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?

Re: How do I stop someone posted spaces in a form?

Posted: Mon Jun 02, 2014 1:40 pm
by Celauran
simonmlewis wrote:How do I check length?
strlen()

I agree, trim should work just as well.

Re: How do I stop someone posted spaces in a form?

Posted: Mon Jun 02, 2014 1:53 pm
by simonmlewis
Not to worry, this one is very cool:

Code: Select all

http://stanislav.it/javascript-display-content-with-delay/

Re: How do I stop someone posted spaces in a form?

Posted: Tue Jun 03, 2014 3:46 am
by simonmlewis
The TRIM doesn't work.
I get this error in my logs:
[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
Line 171 is that line:

Code: Select all

if (empty(trim($message)))
{
}
Am I writing it wrong??

Re: How do I stop someone posted spaces in a form?

Posted: Tue Jun 03, 2014 6:52 am
by Celauran
Yes, you have to assign it to a variable before passing it to empty()

Code: Select all

$message = trim($message);
if (empty($message)) {
... etc