From tom at functionalmedia.com Thu Oct 1 10:24:33 2009 From: tom at functionalmedia.com (Tom Hanlon) Date: Thu, 1 Oct 2009 10:24:33 -0400 Subject: [colug-php] PHP/Javascript empty text box issues In-Reply-To: <24776106.21254304670087.JavaMail.rob@albert3> References: <24776106.21254304670087.JavaMail.rob@albert3> Message-ID: <6C7A59D0-49C3-4EB3-A0A3-2D2A42890318@functionalmedia.com> if (strlen($_POST[search_text])<3) { header( location "previous page?message=no_search_term" ; ## must be at top of page before any content, headers come first } Then before form if ($_GET[message]=="no_search_term") { echo "YOUR SEARCH STRING IS TOO SHORT, please try again"; } The java script stuff works but confuses by adding too many options. So I do not mind a head of the php script with a bunch of error checking and a Location header for a redirect where needed. Possibly setting $_GET values as part of the redirect.. Or a cookie. -- Tom On 30 Sep 2009, at 05:57, Rob Haag wrote: > Hi, I'm working on a search engine for a database, I found that if a > search for whitespace (empty form) is made...it takes a long time > (it does turn up results albeit useless), so I am trying to > implement this as a check... > I have this in my document head (I found it on the web @ http://www.tizag.com/javascriptT/javascriptform.php > : > > > > I tried adding the 'SetValue' to at least try and throw in a default > string (I was gonna change it before putting it up for my client :) ) > I also did have the 'else' section as 'return true;' but I thought a > hard return false may work...it don't (I also read something about > the Geko browser engine not using the 'focus', and it does not > refocus when an empty box is used either. > > > this is my form: >
> > if I submit an empty box, the popup with the alert works, but after > clicking 'ok' it continues with the flow anyway...thus searching for > 'nothing'...taking a long time making debugging quite frustrating :) > Any help/suggestions would be much appreciated, thanks in advance... > > > > -- > Rob Haag > > _______________________________________________ > colug-php mailing list > colug-php at colug.net > http://lists.colug.net/mailman/listinfo/colug-php