Dynamic Validation of Required Fields

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Dynamic Validation of Required Fields

    I am currently using a standard HTML form in which a user must enter certain
    data (required). The form has 2 submit buttons, 1 of which changes the default
    form action to go to a different page. This second submit button does not
    require the same information to be passed as the standard form. I am trying to
    move to using cfforms for better data validation, but I am having difficulty
    turning off the unnecessary required fields for the second submit button.

    Any ideas?

    bifnaked99 Guest

  2. Similar Questions and Discussions

    1. Make DateField required with validation
      I need a DateField to be required so it shows an error if it gains focus and then loses focus without being set. I have seen some examples, but they...
    2. CFINPUT validation & required being bypassed
      Hi all, Ok this one i've never seen before. I've used these tags for years.. So i've setup a simple CFINPUT tag to collect a phone number that is a...
    3. conditional required cfform field + customjavascript validation
      Thanks for responding. Here's the code I'm using to do this. Perhaps it will allow a better understanding of what I'm trying to accomplish. I'm...
    4. email validation without being required
      Here's a more robust regular expression that works with required='no' in Cold Fusion 5. It is adapted from the article:...
    5. Netscape required field validation problems
      I have an interesting problem when I run the following code in Netscape (7.02) vs. IE. This page works great in IE and all my controls bring up the...
  3. #2

    Default Re: Dynamic Validation of Required Fields

    Bif, you will have to create separate functions for each submit button, then
    pass variables created from those functions to a third (Submit) function:
    <input type="Submit" name="subform" value="Save" onclick="maketrue();" >
    <input type="Submit" name="subform1" value="Publish" onclick="checklesson();">
    clicking on either one of these buttons will cause the onclick function and
    the submit function to execute

    Create the functions
    <script language="VBScript">
    lesson=True \\SETS THE PARAMETERS EQUAL TO TRUE, THESE WILL BE USED TO SUBMIT
    THE FORM
    titlecheck=True

    Function checklesson()
    If frmlesson.txttitle.value="" Then \\IF A FORM FIELD IS LEFT NULL
    msgbox "Required Field: Lesson Title",48,"Lessons Learned
    Tool"
    frmlesson.txttitle.focus()
    lesson=False
    titlecheck=False
    Exit Function
    Else
    titlecheck=True
    lesson=True
    End If
    End Function
    \\NOTICE THIS FUNCTION DOES NOT STOP FORM SUBMISSION

    Function maketrue()
    lesson=True
    titlecheck=True
    End Function

    Function frmlesson_onsubmit()
    If frmlesson.txttitle.value="" AND titlecheck=True Then
    msgbox "Required Field: Lesson Title",48,"Lessons Learned Tool"
    frmlesson.txttitle.focus()
    frmlesson_onsubmit=False
    Exit Function
    End If
    If lesson=False Then
    frmlesson_onsubmit=False
    Exit Function
    End If
    End Function
    </script>

    EACH FUNCTION WILL SET THE "titlecheck" OR "lesson" VARIABLE EQUAL TO
    TRUE/FALSE IF NECESSARY, THEN THE FINAL FUNCTION IS USED WHEN THE FORM IS
    SUBMITTED. YOU MUST PLACE THE TRUE/FALSE VARIABLES AND FUNCTIONS CAREFULLY
    BASED UPON HOW THE USER WILL USE THE PAGE. USER COULD CLICK THE SECOND BUTTON,
    THEN CLICK THE FIRST ONE AND BASED UPON THE PLACEMENT IN THE VB SCRIPT, IT
    COULD CAUSE THE FORM TO SUBMIT WHEN IT SHOULD NOT

    bigdawg_ruff Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139