Two dimensional array in HTML

Discussion in 'PHP' started by samirkumardas, Jul 2, 2008.

  1. #1
    is it possible to use two dimensional array in HTML like following code? I have tried but not work in PHP.

    <input type="text" name="import[fields][0]" >
    <input type="text" name="import[fields][1]" >
    <input type="text" name="import[fields][2]" >
     
    samirkumardas, Jul 2, 2008 IP
  2. clarky_y2k3

    clarky_y2k3 Well-Known Member

    Messages:
    114
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    108
    #2
    It does work...

    Here's example code:
    
    <?php
    if ( isset($_POST['submit']) )
    {
        print_r($_POST['field']); 
    }
    ?>
    
    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <input type="text" name="field[one][1]" />
    <input type="text" name="field[one][2]" />
    <input type="text" name="field[one][3]" />
    <br /><br />
    <input type="text" name="field[two][1]" />
    <input type="text" name="field[two][2]" />
    <input type="text" name="field[two][3]" />
    <br /><br />
    <input type="submit" name="submit" />
    </form>
    
    PHP:
    Here's the output:
     
    clarky_y2k3, Jul 2, 2008 IP
  3. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #3
    <?php

    $import = array('fields' => array('a','b','c','d'));

    ?>

    <input type="text" name="<?php echo $import['fields'][0];?>" >
    <input type="text" name="<?php echo $import['fields'][1];?>" >
    <input type="text" name="<?php echo $import['fields'][2];?>" >
     
    php-lover, Jul 2, 2008 IP
  4. samirkumardas

    samirkumardas Banned

    Messages:
    123
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi Thanks for the reply.

    I just checked and found it working If I tried it normally. But It does not work in smarty? I just simply add this form in smarty and found following result.


    <form method="post" >

    <input type="text" name="field[two][1]" value="11"/>
    <input type="text" name="field[two][2]" value="22"/>
    <input type="text" name="field[two][3]" value="33"/>
    <input type="hidden" name="mode" value="upload_action"/>
    <input type="submit" name="submit" id="submit_id" value="Import" />
    </form>

    Result:

    Array ( [two] => Array )
     
    samirkumardas, Jul 2, 2008 IP