Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Preventing Blank Inquiries

  1. #1
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    620
    Thanks
    274
    Thanked 14 Times in 14 Posts

    Default Preventing Blank Inquiries

    I am using the following little script to make sure people fill in the required fields in an inquiry form:

    <script language=Javascript type="text/javascript">
    function validate() {
    if (document.infoform.name.value == "") {
    alert("Please fill in your name.");
    return false;
    }
    if (document.infoform.email.value == "") {
    alert("Please fill in your email address.");
    return false;
    }
    return true;
    }
    </script>

    It seems to work when I test it; nevertheless, a lot of blank inquiries still get through. I am wondering if this could be bots somehow messing with it, or people who have javascript turned off. Is there a better way to prevent blank entries? I don't want to discourage people from making inquiries by making them jump through too many hoops.

    Thanks for your help. erin

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Javascript is not very reliable for this, and it is recommended that you use a server side fallback to check for blank fields that should be required.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    620
    Thanks
    274
    Thanked 14 Times in 14 Posts

    Default

    What's a server side fallback?

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    How is your form being submitted? Is it through a php script (like form.php), or some other form of server side scripting. If so, you would want to put a snippet of code in that file to check to see if there are blank submissions or whatnot.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    620
    Thanks
    274
    Thanked 14 Times in 14 Posts

    Default

    Yes, a php script, but it comes into play only after the form is submitted. I don't know how to do a pop-up window in php so would have to send them to an error page and by then the person would have gone away. Is there an easy way to do the php check? If not, can't I just improve that javascript? What do other people do? Thanks, erin

  6. #6
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Quote Originally Posted by kuau View Post
    Yes, a php script, but it comes into play only after the form is submitted. I don't know how to do a pop-up window in php so would have to send them to an error page and by then the person would have gone away. Is there an easy way to do the php check? If not, can't I just improve that javascript? What do other people do? Thanks, erin
    submit it to a validation function and in the validation function you check for each required field. if that field contains an error you place the a message containing the field into an error array.

    at the very end of the validation function after you have done all of your checks on individual fields you do one last check to see if the error array has been populated. if there are values in the error array you send the user back to the form notifying them of the errors (typically its done in a list in red / outstanding color)

    This creates some extra work but you shouldn't force the user to re-enter every single value again, but rather save each of the form fields and populate all of the ones that are correct with the previous values to prevent duplication, and call attention to the fields that are in error (typically with a different background color)

    That last bit about auto-populating the old values will create less frustration for the user, but it's only to help keep the user from being frustrated and leaving your page...

    that may have been hard to understand so here is some psuedo code
    Code:
    <?php 
    
    function process_form()
    {
         $error = array();
         if(field required)
         {
               condition
               if( bad_condition )
               {
                     $error[] = "Message about required field";
               }
         }
         ...
    
         if(isset($error))
         {
                display_form($errors);
         }
    }
    
    function display_form($error)
    {
    
         if($error)
         {
              echo "<ul>";
              foreach($error as $err)
             {
                    echo "\n\t<li>". $err ."</li>";
              }
              echo "</ul>";
    ?>
    --- REST OF FORM INFORMATION HERE ---
    <?php
         }
    }
    
    
    if(submitted)
    {
         process_form();
    }
    else
    {
         display_form();
    }

  7. #7
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    620
    Thanks
    274
    Thanked 14 Times in 14 Posts

    Default

    Dear Boogey:

    Wow, that was a bit over my head, but when I get some time I'll see if I can figure out what it is. I know only the tiniest bit of php... I'm just a good mimmick. ie. if I have some code that is correct as a model, I can usually apply it to another situation but, out of context, it might as well be Japanese. Am I supposed to insert that into the html code? I can't really focus on it right now (working) but shall try later. Thanks for your help. Aloha, erin

  8. #8
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    If you can post the code that you have now that processes the form, we can take a look at it and modify it to have the correct field checking snippet.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  9. #9
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    620
    Thanks
    274
    Thanked 14 Times in 14 Posts

    Default

    What a sweetheart you are. I have to admit not knowing how to post code so neatly as Boogy did. It made a mess when I tried to put it here. So maybe you can steer me to that tutorial, and also clarify if it is the form code in the web-facing page or the php code that runs when you hit Submit that you want to see. Mahalo plenty, erin

  10. #10
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    you can post code like I did by using

    [code]

    your_stuff

    [/code]

    clarify if it is the form code in the web-facing page or the php code that runs when you hit Submit that you want to see
    both would be great.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •