1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Validation of contact form fields

Discussion in 'C#' started by adell50, Oct 8, 2009.

  1. #1
    A good chap suggested that I validate the contact form on my site with the suggestion below:

    "...On the Contact us page: The form sends data to the server even when there's invalid/empty fields. I know you have set the blue "Some information is missing." text but (you probably know what I'm gonna say) validate each field on the client side first, give specific warnings of each field, never submit to server invalid forms, keep your server validation too for double protection..."

    Im not exactly sure where to start. Anyone have any ideas?

    Many thanks!!!
     
    adell50, Oct 8, 2009 IP
  2. rayqsl

    rayqsl Active Member

    Messages:
    91
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    53
    #2
    I think the good chap is talking about Javascript.

    Javascript runs on the client and you can pop up alert boxes if you detect any errors.

    I haven't really done this myself (I've changed a few scripts but that was a long time ago).

    As usual, w3schools is a good starting point http://www.w3schools.com/jS/js_form_validation.asp.

    :)
     
    rayqsl, Oct 8, 2009 IP
  3. adell50

    adell50 Peon

    Messages:
    165
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    cool...thanks! ill have a look at the w3
     
    adell50, Oct 8, 2009 IP
  4. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #4
    There is no reason that you have to do this... You absolutely have to validate the data server-side anyway, i guess it just reduces the work that the server has to do and makes things just a little bit easier for the user at the front-end. But unless you have a huge amount of requests, you have to ask yourself if it is worth the extra effort, assuming that a lot of the requests will be valid anyway.
     
    camjohnson95, Oct 9, 2009 IP
  5. adell50

    adell50 Peon

    Messages:
    165
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    good point. we currently do not get a ton of requests, but hopefully that will change in the future :D

    Thanks again!
     
    adell50, Oct 9, 2009 IP
  6. Free Born John

    Free Born John Guest

    Messages:
    111
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You don't see too much javascript validation nowadays. I really wouldn't bother with it.
     
    Free Born John, Oct 11, 2009 IP
  7. Sapphiro

    Sapphiro Well-Known Member

    Messages:
    1,242
    Likes Received:
    61
    Best Answers:
    0
    Trophy Points:
    175
    #7
    Do something like this (in the programming language that you're using)

    
    if (strlen($_GET['field1']) == 0 || strlen($_GET['field2]) == 0)
    {
       $valid = false;
    }
    
    if (valid == true)
    {
      // mail() code here
    }
    else
    {
       // echo "your form is not sent".
    }
    Code (markup):

    Hope it helps. :) Of course, "field1" and "field2" should be replaced with the id you gave to the input fields.
    
    <input id="field1" name="field1" ........
    
    Code (markup):
     
    Sapphiro, Oct 11, 2009 IP
  8. adell50

    adell50 Peon

    Messages:
    165
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Thank you very much for the tip! I'll give it a try :)
     
    adell50, Oct 11, 2009 IP
  9. leebari

    leebari Peon

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    It is important to validate email address: Create a function that would check if @ and . (dot) symbols are present. To prevent spamming you could create a function that would check if explicit words are present, specially in "notes" field.
     
    leebari, Oct 16, 2009 IP
  10. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Seeing as the site runs in .Net then just use the .Net validators as you can place these on the page to run clientside and then with a single line do the serverside validation as it uses the same control. See http://www.asp101.com/lessons/validation.asp for the main .Net validators
     
    AstarothSolutions, Oct 16, 2009 IP
  11. adell50

    adell50 Peon

    Messages:
    165
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #11
    @Astaroth - thnak you very much for the tip. I'll look into those val..cheers!
     
    adell50, Oct 16, 2009 IP