Use of [ and ] within id or name attribute of <input /> tag

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Martin Lucas-Smith

    Use of [ and ] within id or name attribute of <input /> tag



    I am wanting to know whether [ and ] are XHTML1-valid characters for use
    within an id attribute and/or a name attribute.



    (e.g. see line 77) suggests that it is valid, but the spec suggests that
    it is not.


    More detail:

    I have a form containing a variety of input elements, including a checkbox
    array.

    For ease of processing the form, it would be helpful if the name of each
    element in the checkbox array could include [ ] e.g.

    <input type="checkbox" name="formname[checkbox][number]" />

    However, looking at the HTML4 spec, which XHTML1.0Transit ional piggy-backs
    onto, the specification suggests that [ and ] are not valid characters for
    use within this:



    "ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
    followed by any number of letters, digits ([0-9]), hyphens ("-"),
    underscores ("_"), colons (":"), and periods (".")."

    However, a page I have online at present which uses [ ] does validate to
    XHTML1.0Transit ional:



    eg. line 77 contains name="main[function]"

    Is [ and ] therefore valid?




    Martin Lucas-Smith www.geog.cam.ac.uk/~mvl22


  • Martin Honnen

    #2
    Re: Use of [ and ] within id or name attribute of &lt;input /&gt; tag



    Martin Lucas-Smith wrote:
    [color=blue]
    >
    > I am wanting to know whether [ and ] are XHTML1-valid characters for use
    > within an id attribute and/or a name attribute.
    >
    > http://validator.w3.org/check?uri=ht...ss=1&verbose=1
    >
    > (e.g. see line 77) suggests that it is valid, but the spec suggests that
    > it is not.
    >
    >
    > More detail:
    >
    > I have a form containing a variety of input elements, including a checkbox
    > array.
    >
    > For ease of processing the form, it would be helpful if the name of each
    > element in the checkbox array could include [ ] e.g.
    >
    > <input type="checkbox" name="formname[checkbox][number]" />
    >
    > However, looking at the HTML4 spec, which XHTML1.0Transit ional piggy-backs
    > onto, the specification suggests that [ and ] are not valid characters for
    > use within this:
    >
    > http://www.w3.org/TR/html401/types.html#type-name
    >
    > "ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
    > followed by any number of letters, digits ([0-9]), hyphens ("-"),
    > underscores ("_"), colons (":"), and periods (".")."
    >
    > However, a page I have online at present which uses [ ] does validate to
    > XHTML1.0Transit ional:
    >
    > http://validator.w3.org/check?uri=ht...ss=1&verbose=1
    >
    > eg. line 77 contains name="main[function]"
    >
    > Is [ and ] therefore valid?[/color]

    When you look at

    you will see that the name attribute of <input> is of type CDATA
    therefore for XHTML 1.0 transitional the [] in a name attribute value of
    an <input> element will pass validation with an XML parser.
    The id attribute is defined to be of type ID and that doesn't allow [ or ].
    --

    Martin Honnen


    Comment

    • Martin Lucas-Smith

      #3
      Re: Use of [ and ] within id or name attribute of &lt;input /&gt; tag



      [Summary: Can anyone point me to a definitive reference of where the
      allowed characters for a valid XHTML name attribute (of an input/form) tag
      is, so I can make a regexp from this (or even also provide me with a
      regexp!)?]


      A while ago I posted to this list wanting to know whether [ and ] are
      XHTML1-valid characters for use within an id attribute and/or a name
      attribute. I need to apply this more generally now beyond just [].

      Ultimately, I'm trying to get an regexp for validating a form API-supplied
      name for both an input tag (<input name="something " ... /> and for a form
      name <form name="something ">, i.e. in PHP



      $formName = 'name';

      $regexp = '[something]';
      if (!ereg ($regexp, $formName)) {
      'The form name must consist of characters....
      }




      I understand that in HTML4, [] and are allowed this is not the case:
      [color=blue][color=green]
      > > http://www.w3.org/TR/html401/types.html#type-name
      > >
      > > "ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
      > > followed by any number of letters, digits ([0-9]), hyphens ("-"),
      > > underscores ("_"), colons (":"), and periods (".")."[/color][/color]


      But that in XHTML the allowed characters are different (as I have been
      told they include []) :

      [color=blue]
      > When you look at
      > http://www.w3.org/TR/xhtml1/dtds.htm...onal.dtd_input
      > you will see that the name attribute of <input> is of type CDATA
      > therefore for XHTML 1.0 transitional the [] in a name attribute value of
      > an <input> element will pass validation with an XML parser. The id
      > attribute is defined to be of type ID and that doesn't allow [ or ]. --[/color]

      However, I can't see where exactly the CDATA type is defined for XHTML
      Transitional, which is the doctype I'm using? Therefore:


      ** Can anyone point me to a definitive reference of where the allowed
      characters for a valid XHTML name attribute (of an input/form) tag is, so
      I can make a regexp from this (or even also provide me with a regexp!)? **



      Martin

      Comment

      • Jim Dabell

        #4
        Re: Use of [ and ] within id or name attribute of &lt;input /&gt; tag

        Martin Lucas-Smith wrote:
        [color=blue]
        > [Summary: Can anyone point me to a definitive reference of where the
        > allowed characters for a valid XHTML name attribute (of an input/form) tag
        > is, so I can make a regexp from this (or even also provide me with a
        > regexp!)?][/color]
        [snip][color=blue]
        > I understand that in HTML4, [] and are allowed this is not the case:
        >[color=green][color=darkred]
        >> > http://www.w3.org/TR/html401/types.html#type-name
        >> >
        >> > "ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
        >> > followed by any number of letters, digits ([0-9]), hyphens ("-"),
        >> > underscores ("_"), colons (":"), and periods (".")."[/color][/color][/color]
        [snip]

        You are confusing data types with attributes. The name attribute for the
        <input> element type is clearly listed as being CDATA, not ID or NAME
        tokens:

        <URL:http://www.w3.org/TR/html401/interact/forms.html#h-17.3>
        <URL:http://www.w3.org/TR/html401/interact/forms.html#h-17.4>

        The only real restriction on what characters can appear in form control
        names is when a form is submitted with GET:

        "The "get" method restricts form data set values to ASCII characters."

        -- <URL:http://www.w3.org/TR/html401/interact/forms.html#h-17.13.1>

        [color=blue]
        > However, I can't see where exactly the CDATA type is defined for XHTML
        > Transitional, which is the doctype I'm using?[/color]
        [snip]

        <URL:http://www.w3.org/TR/REC-xml#attdecls>

        --
        Jim Dabell

        Comment

        • Martin Lucas-Smith

          #5
          Re: Use of [ and ] within id or name attribute of &lt;input /&gt; tag


          [color=blue][color=green]
          > > [Summary: Can anyone point me to a definitive reference of where the
          > > allowed characters for a valid XHTML name attribute (of an input/form)
          > > tag is, so I can make a regexp from this (or even also provide me with
          > > a regexp!)?][/color]
          >
          > You are confusing data types with attributes. The name attribute for
          > the <input> element type is clearly listed as being CDATA, not ID or
          > NAME tokens:[/color]

          I must confess I don't fully understand how the spec is read :), hence my
          question.

          [color=blue]
          > The only real restriction on what characters can appear in form control
          > names is when a form is submitted with GET:
          >
          > "The "get" method restricts form data set values to ASCII characters."
          >
          > -- <URL:http://www.w3.org/TR/html401/interact/forms.html#h-17.13.1>[/color]


          Erm, I'm strictly referring to what appears as XXX in the following:

          <input name="xxx" ... />

          Can anyone supply an unambiguous reference/regexp as to what xxx can be
          for the page still to validate as XHTML?



          Martin

          Comment

          Working...