SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jul 2002
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    error handling and message boxes

    i am coding in VBScript. i am coding for an online survey. for error handling (eg if the user forgets to fill out a field), is it possible to ensure all fields have been filled out BEFORE clicking the submit button? i wish for the user to be notified via a MESSAGE BOX, how would i go about this(using VBScript)?
    thank you!

  2. #2
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You probably wouldn't in truth. You'd use JavaScript. There's no sense in making something like that server-side when it can be client-side. It puts an unnecessary load on everything! There are plenty of examples of JavaScript doing this -- I come across it a lot. A quick look on Google for 'JavaScript form verification' or something similar is sure to turn up the perfect script.

  3. #3
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's pretty easy to do, just write a function(s) that checks that each box has been filled (and even that any fields you can check are valid)

    Then when the submit button is hit, if anything is missing a javascript alert pops up

    PHP Code:
    <SCRIPT LANGUAGE="JavaScript">
    /** Checks if field is blank */
    function isNotEmpty(field
    {
        if (
    field.value == "")
        {
            
    alert ("The field is blank. Please Complete the field.")
            
    field.focus();
            return 
    false;
        }
        else
        return 
    true;
    }
    </SCRIPT> 
    and call it with this inside each form element:

    PHP Code:
    onChange="return isNotEmpty(this);}" 
    I use it instead of doing it serverside, makes it easier on both sides

  4. #4
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You should also think about the security of only using Javascript. As this can be turned off by the end user. and leave you open to people filling in an empty form.

    What I 'try' to do, is create a Javascript script very similiar to Platz and only when that returns no errors you complete checks using VB code. Its usually more pertinent checks like, if its an integer field has only an integer been entered. If it an email field has a valid email been added (xxx@yyy.zz format) that type of thing, basically looking for anything malicious.

    The only problem being I don't know VB code and therefore can only offer this as a 'way' to do it I can't help with the 'how'

    Sarah
    Regular user

  5. #5
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have to say IMO if someone's gonna mess with your form, they're gonna mess with you form. You can't stop people leaving FALSE data. All you can do really is remind geuine users if they've missed a field. HTMLEncode in VB at the server-side just to kill any potentially malicious stuff typed into a form field is a good idea, but that's a separate issue -- and one line of code:

    Code:
    strFormField = Server.HTMLEncode(Request.Form("form_field"))
    G


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
  •