Is it valid to have a html form inside another html form?

前端 未结 14 1791
故里飘歌
故里飘歌 2020-11-22 06:01

Is it valid html to have the following:

相关标签:
14条回答
  • 2020-11-22 06:55

    You can answer your own question very easily by inputting the HTML code into the W3 Validator. (It features a text input field, you won't even have to put your code on a server...)

    (And no, it won't validate.)

    0 讨论(0)
  • 2020-11-22 06:55

    If you need your form to submit/commit data to a 1:M relational database, I would recommend creating an "after insert" DB trigger on table A that will insert the necessary data for table B.

    0 讨论(0)
  • 2020-11-22 06:58

    no, see w3c

    0 讨论(0)
  • 2020-11-22 07:00

    No, it is not valid. But a "solution" can be creating a modal window outside of form "a" containing the form "b".

    <div id="myModalFormB" class="modal">
        <form action="b">
            <input.../>
            <input.../>
            <input.../>
            <button type="submit">Save</button>
        </form>
    </div>
    
    <form action="a">
        <input.../>
        <a href="#myModalFormB">Open modal b </a>
        <input.../>
    </form>
    

    It can be easily done if you are using bootstrap or materialize css. I'm doing this to avoid using iframe.

    0 讨论(0)
  • 2020-11-22 07:01

    No, the HTML specification states that no FORM element should contain another FORM element.

    0 讨论(0)
  • 2020-11-22 07:01

    As workaround you could use formaction attribute on submit button. And just use different names on your inputs.

    <form action="a">
    <input.../>
        <!-- Form 2 inputs -->
        <input.../>
        <input.../>
        <input.../>
        <input type="submit" formaction="b">
    
    </form>
    <input.../>
    
    0 讨论(0)
提交回复
热议问题