Skip to main content
Legend
April 21, 2010
Question

cfinput and slash

  • April 21, 2010
  • 1 reply
  • 845 views

I use <cfinput> all over the place for forms. When cfinput processes, coldfusion includes an <input... /> in the final page that the user receives. Is there a way to tell coldfusion not to include the closing input tag slash? This is invalid syntax for the DOCTYPE we are using and the W3C validation utility flags this as an error.

I'm using cf8 and cf9 and both do the same.

    This topic has been closed for replies.

    1 reply

    Inspiring
    April 21, 2010

    Crikey: which doctype are you using that doesn't permit self-closing tags?  Just out of interest.

    I think you had better raise a bug with Adobe.  My feeling is that CF should only provide the self-closing tag if that's how one forms the <cfinput> (err... <cfinput />, I guess!) tag in the first place.  Whilst most situations will call for XHTML compliance these days, it would be better to give the flexibility to have plain old HTML tags if one wants (for whatever reason... such as your situation).

    http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbugtracker/main.html

    --
    Adam

    Legend
    April 21, 2010

    We are currently using the following:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

    W3C validator does not like <input... /> or <br />, or any other self terminating tag with a slash.

    I agree, I think the cfinput tag should only include the slash if the programmer coded the cfinput tag with the slash -- but it does not. It seems to assume the programmer didn't know what he was doing and instead try to be helpful by cleaning up the code.

    Inspiring
    April 21, 2010

    Strange.  When I try to validate a doc with that as its doctype and <input/> and <br/> tags, it validates on the W3C validator just fine.  I get a warning for each of them, but a warning is simply that: just a warning.  It still gets the W3C stamp of approval.  Did you get errors or warnings?

    This is the CFML code I used:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
        <title>Test</title>
    </head>
    <body>
        <cfform action="#CGI.script_name#" method="post">
            <p><cfinput type="text" name="txt1" value=""><br /></p>
            <p><cfinput type="submit" name="btnSubmit1" value="Submit"></p>       
        </cfform>

    </body>
    </html>

    This was the resultant mark-up:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head><script type="text/javascript" src="/CFIDE/scripts/cfform.js"></script>
    <script type="text/javascript" src="/CFIDE/scripts/masks.js"></script>

         <title>Test</title>
    <script type="text/javascript">
    <!--
        _CF_checkCFForm_1 = function(_CF_this)
        {
            //reset on submit
            _CF_error_exists = false;
            _CF_error_messages = new Array();
            _CF_error_fields = new Object();
            _CF_FirstErrorField = null;


            //display error messages and return success
            if( _CF_error_exists )
            {
                if( _CF_error_messages.length > 0 )
                {
                    // show alert() message
                    _CF_onErrorAlert(_CF_error_messages);
                    // set focus to first form error, if the field supports js focus().
                    if( _CF_this[_CF_FirstErrorField].type == "text" )
                    { _CF_this[_CF_FirstErrorField].focus(); }

                }
                return false;
            }else {
                return true;
            }
        }
    //-->
    </script>
    </head>
    <body>
         <form name="CFForm_1" id="CFForm_1" action="/shared/cf/cfml/tags/forms/input/htmlCompliance.cfm" method="post" onsubmit="return _CF_checkCFForm_1(this)">
              <p><input name="txt1" id="txt1"  type="text" /><br /></p>
              <p><input name="btnSubmit1" id="btnSubmit1"  type="submit" value="Submit" /></p>          
         </form>


    </body>
    </html>

    And that all got the green light at http://validator.w3.org/#validate_by_input

    CF makes a lot of assumptions about the developer not knowing what (s)he is doing.  Unfortunatelty, with CF developers, this is probably the right position to have 90% of the time.  Sux for the other 10% of people though ;-)

    --

    Adam