[colug-php] PHP/Javascript empty text box issues
Tom Hanlon
tom at functionalmedia.com
Thu Oct 1 10:24:33 EDT 2009
<?
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
> :
>
> <script type='text/javascript'>
> function notEmpty(elem, helperMsg){
> if(elem.value.length == 0){
> alert(helperMsg);
> elem.SetValue("Bill Gates Sucks");
> elem.focus();
> return false;
> }
> return false;
> }
> </script>
>
> 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:
> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
> <label for="search_text"> Search in Database</label><br />
> <input type="text" name="search_text" <?php
> if(isset($_POST['search_text'])) echo 'value="'.
> $_POST['search_text'].'"'; ?> id='req1'/>
> <input type="submit"
> onclick="notEmpty(document.getElementById('req1'),
> 'Please Enter a Value (Searching for Nothing takes a really long
> time.')"
> value="Search" class="btn2"/>
> </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
More information about the colug-php
mailing list