HTML form with multiple hidden control elements of the same name

前端 未结 8 2102
-上瘾入骨i
-上瘾入骨i 2020-11-27 06:14

Is it legal to have an HTML form with more than one \"hidden\" control element with the same name? I expect to get the values of all of these elements at the server. If it i

8条回答
  •  时光说笑
    2020-11-27 06:32

    Specifically for PHP I made some tests with array names in hidden inputs and I share here my results:

    
    
      
        
        Post Hidden 2D Arrays
      
      
        
    <?php print_r($_POST); ?>

    Submitting the form generates the next result:

    Array
    (
    [elem] => Array
        (
            ['name'] => Array
                (
                    [0] => first
                    [1] => second
                    [2] => third
                    [3] => fourth
                )
            ['type'] => Array
                (
                    [0] => normal
                    [1] => classic
                    [2] => regular
                    [3] => basic
                )
            ['size'] => Array
                (
                    [0] => 4
                    [1] => 7
                    [2] => 3
                    [3] => 6
                )
            ['temp'] => Array
                (
                    [0] => triangle
                    [1] => square
                    [2] => hexagon
                    [3] => circle
                )
        )
    [sendtest] => Test
    )
    

    After viewing this result I made more tests looking a better arrange of array values and ended with this (I will show only the new hidden inputs):

        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    

    Obtaining this result after submitting form:

    Array
    (
    [elem] => Array
        (
            [0] => Array
                (
                    ['name'] => first
                    ['type'] => normal
                    ['size'] => 4
                    ['temp'] => triangle
                )
            [1] => Array
                (
                    ['name'] => second
                    ['type'] => classic
                    ['size'] => 7
                    ['temp'] => square
                )
            [2] => Array
                (
                    ['name'] => third
                    ['type'] => regular
                    ['size'] => 3
                    ['temp'] => hexagon
                )
            [3] => Array
                (
                    ['name'] => fourth
                    ['type'] => basic
                    ['size'] => 6
                    ['temp'] => circle
                )
        )
    [sendtest] => Test
    )
    

    I hope this helps a few.

提交回复
热议问题