Form Validation

Discussion in 'Programming' started by Jamie18, Aug 13, 2007.

  1. #1
    just looking for a quick answer to this. this is probably something elementary to most CF programmers.

    i'm attempting to validate a form, i've got an arbitrary number of email fields in the form populated by a query.. so each email field is named 'email#currentrow#'

    now when i'm trying to loop over all the emails to validate them i first want to ensure there are no malicious characters.. i.e. i want to throw an error if someone were to write something along the lines of '<script ...' in the field..
    the problem that i'm having is i don't know how to get what's inside that form field other than using 'evaluate("email#loopindex#")'.. which goes ahead and runs whatever malicious code is inside the field before it's validated.

    so i'm looking for something to replace the evaluate() method... any ideas?
     
    Jamie18, Aug 13, 2007 IP
  2. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The "form" or "url" scope can be accessed with array notation

    
    <cfoutput>#FORM["email"& loopindex]#</cfoutput>
    
    Code (markup):
     
    cfStarlight, Aug 13, 2007 IP
  3. Jamie18

    Jamie18 Peon

    Messages:
    201
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thank you for the quick reply.
    i'll give it a shot
     
    Jamie18, Aug 13, 2007 IP
  4. Jamie18

    Jamie18 Peon

    Messages:
    201
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    looks like it's working perfectly..
    i simply replaced the 'evaluate("email#loopindex#")'s in my code with 'FORM["email"& loopindex]'s and all is well.. thanks a lot
     
    Jamie18, Aug 13, 2007 IP
  5. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Glad to help. CF guidelines recommends using array notation over evaluate anyway because evaluate is a slightly more expensive operation.
     
    cfStarlight, Aug 13, 2007 IP