Re: Same named input elements in different forms?

Discussion in 'HTML' started by Beauregard T. Shagnasty, Dec 28, 2009.

  1. Ed Jay wrote:

    > Is it allowable to use the same name for multiple input elements if
    > they're in different forms?


    Probably. Possibly. But since they are in different forms, why do you
    want to muddy the waters over in your (unnamed) action script?

    $field1 = $_POST['field1'];

    Umm, which one? Think about maintenance in six months...

    --
    -bts
    -tossing 2ยข more, 'cause I can
    Beauregard T. Shagnasty, Dec 28, 2009
    #1
    1. Advertising

  2. Beauregard T. Shagnasty

    Doug Miller Guest

    In article <hhb9pt$ola$-september.org>, lid wrote:
    >Ed Jay wrote:
    >
    >> Is it allowable to use the same name for multiple input elements if
    >> they're in different forms?

    >
    >Probably. Possibly. But since they are in different forms, why do you
    >want to muddy the waters over in your (unnamed) action script?
    >
    >$field1 = $_POST['field1'];
    >
    >Umm, which one? Think about maintenance in six months...
    >

    Since they are in different forms, there's no reason to suppose that the same
    script processes each form.
    Doug Miller, Dec 28, 2009
    #2
    1. Advertising

  3. Doug Miller wrote:

    > lid wrote:
    >> Ed Jay wrote:
    >>> Is it allowable to use the same name for multiple input elements if
    >>> they're in different forms?

    >>
    >> Probably. Possibly. But since they are in different forms, why do
    >> you want to muddy the waters over in your (unnamed) action script?
    >>
    >> $field1 = $_POST['field1'];
    >>
    >> Umm, which one? Think about maintenance in six months...
    >>

    > Since they are in different forms, there's no reason to suppose that
    > the same script processes each form.


    ...further muddying the waters.

    --
    -bts
    -Four wheels carry the body; two wheels move the soul
    Beauregard T. Shagnasty, Dec 28, 2009
    #3
  4. Beauregard T. Shagnasty wrote:
    > Ed Jay wrote:
    >
    >> Is it allowable to use the same name for multiple input elements if
    >> they're in different forms?

    >
    > Probably. Possibly. But since they are in different forms, why do you
    > want to muddy the waters over in your (unnamed) action script?
    >
    > $field1 = $_POST['field1'];
    >
    > Umm, which one? Think about maintenance in six months...
    >


    If the forms are submitted to different URLs, it doesn't matter. If they
    are submitted to the same URL, then either the forms are meant to serve
    as alternate interfaces to the same handler, in which case they are
    *supposed* to be indistinguishable, or they aren't, in which case it's
    hard to imagine that the developer hasn't figured out that they two
    forms need to be routed somehow to two different handlers.
    Harlan Messinger, Dec 28, 2009
    #4
  5. Ed Jay wrote:

    > I'll answer everyone's response with this...


    As usual, the situation would have been much clearer if you had posted the
    URL, and the URL would still be useful.

    > I have two forms contained on the same page. A credit memo form and a
    > debit memo form.


    That's possible, but why not put them on separate pages? What are the odds
    that both of them are needed at the same time?

    > The visible form depends on the user's menu choice.


    Do you mean that you rely on CSS _and_ scripting to make one of the forms
    invisible? In effect, you have one form per page, but you do that in an
    unnecessarily complicated and unreliable way.

    > Each form contains a single checkbox element, which when checked, is
    > the flag to send the memo to the recipient of the credit or debit
    > when whichever form is submitted.


    I don't quite see why you need it, but presumably sending the memo is an
    optional feature in form data processing.

    > I thought of the complexity of sorting things out at my Perl script
    > end, and decided it would be much easier if I could simply use two
    > input elements with the same name in each of the two forms.


    I can't believe it can be "much easier" - you would probably need just one
    conditional expression.

    You _can_ use the same name="..." attribute, of course (though not the same
    id="..." attribute). And there's no particular reason to use different
    attributes. The same applies to the approach of using two separate pages, as
    you would probably generate them by the same Perl script, just with some
    parameterization.

    > So, I asked my question, with enough information given to solicit a
    > simple yes/no answer.


    And the correct answer was given, but the question was wrong, in practical
    terms. Well, rather irrelevant, let us say. The question you now implicitly
    (well, very implicitly...) asked is much more important: should you have two
    forms on the same page?

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
    Jukka K. Korpela, Dec 29, 2009
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christopher Brewster
    Replies:
    5
    Views:
    329
    John Machin
    Nov 14, 2008
  2. bluebaron
    Replies:
    3
    Views:
    722
    Jonathan N. Little
    Nov 4, 2009
  3. Harlan Messinger
    Replies:
    3
    Views:
    510
    dorayme
    Dec 28, 2009
  4. Qi
    Replies:
    7
    Views:
    793
  5. Guest
    Replies:
    2
    Views:
    169
    Foo Man Chew
    Dec 29, 2003
Loading...

Share This Page