Skip to main content
Inspiring
September 3, 2015
Answered

Email field validation not working for <cfinput>

  • September 3, 2015
  • 3 replies
  • 664 views

My form has input fields for first and last names and for an email address. Form validation for email is not working people are entering First Name" 1, Last Name: 1, and email: 1 and the action for the form is completing without catching the error.

The action  invokes a <CFMail> to send the information to the office manager.

Any thoughts?.

    This topic has been closed for replies.
    Correct answer James Moberg

    Are people really entering "1" into the form or are bots (or PCI scanners) posting those values directly to your action script?  Prior to sending CFMail, perform an server-side isValid("email") check to ensure that it's actually a valid email address.

    Regarding the use of CFINPUT, I'd recommend using an alternative like jQuery Validation plugin.  You'll have more control over the validation and gain skills that you can apply to any HTML (even static).

    http://jqueryvalidation.org/

    3 replies

    James Moberg
    James MobergCorrect answer
    Inspiring
    September 3, 2015

    Are people really entering "1" into the form or are bots (or PCI scanners) posting those values directly to your action script?  Prior to sending CFMail, perform an server-side isValid("email") check to ensure that it's actually a valid email address.

    Regarding the use of CFINPUT, I'd recommend using an alternative like jQuery Validation plugin.  You'll have more control over the validation and gain skills that you can apply to any HTML (even static).

    http://jqueryvalidation.org/

    BKBK
    Community Expert
    Community Expert
    September 3, 2015

    Follow Wolfshade's suggestion.

    Just to help you check, the following simple code works as expected:

    <cfdump var="#form#">

    <cfform>

      E-mail: <cfinput type="text" name="email" validate="email" message="Enter valid e-mail address."><br>

      First name: <cfinput type="text" name="fname" validate="regex" pattern="[a-zA-Z]{2}" message="First name must contain at least 2 letters."><br>

      Last name: <cfinput type="text" name="lname" validate="regex" pattern="[a-zA-Z]{2}" message="Last name must contain at least 2 letters."><br>

      <cfinput type="submit" name="sbmt" value="Send">

    </cfform>

    WolfShade
    Legend
    September 3, 2015

    First thought would be to check the browser error console to see if there are any messages.

    Second thought would be (please don't hate me), "don't use cfinput; use regular form and inputs and use JavaScript IN ADDITION TO server-side validation."

    V/r,

    ^_^