Jump to content


Photo

HTML Form & Multi-Dimensional Arrays


  • Please log in to reply
3 replies to this topic

#1 micxnet

micxnet

    Newbie

  • Members
  • Pip
  • 6 posts
  • LocationAustralia

Posted 25 February 2006 - 09:32 PM

Hi there,

I am currently buiding a part generator page, that allows you to construct multiple parts at one time. Basically it is made up of two multiple select boxes with another text box with the quantity of base products to a part. I require those two multi-select drop down's to be mutli-dimensional arrays for the form processor I developed.

Unfortunately, it wasn't as easy as adding []. So how would I go about trying to do this?

Here is my code for the HTML form:

<table class="main" cellpadding="0" cellspacing="10" align="center">
<tr><td><h1>Base + Parts Dashboard</h1></td></tr>
<tr><td>
<table class="quick" cellpadding="0" cellspacing="10" align="center" width="450">
<tr><td colspan="3" valign="top"><h2>Parts Management</h2></td></tr>
<form name="partgen" action="index.php?i=99" method="post">

<tr><td valign="top">Select Base(s):</td><td><select class="drop" name="field[part_base_id[]]" multiple="multiple" size="5"><?=selectgen('base');?></select></td><td><input name="name[part_base_id]" type="hidden" value="Select Base(s)" /></td></tr>

<tr><td valign="top">Select Make(s):</td><td><select class="drop" name="field[part_make_id[]]" multiple="multiple" size="5"><?=selectgen('make');?></select></td><td><input name="name[part_make_id]" type="hidden" value="Select Make(s)" /></td></tr>

<tr><td>Kit Count:</td><td><input type="text" name="field[part_kit_count]" class="text"/></td><td><input name="name[part_kit_count]" type="hidden" value="Kit Count" /><b>i.e 2</b></td></tr>

<tr><td colspan="3" align="center"><input type="submit" name="submit" value="Submit" class="submit" /></td></tr>
<input name="table" type="hidden" value="part" />
<input name="key" type="hidden" value="part_id" />
</form>
</table></td></tr>
</table>

Thanks in advance.

#2 hitman6003

hitman6003

    Advanced Member

  • Members
  • PipPipPip
  • 1,807 posts

Posted 25 February 2006 - 11:15 PM

Your html is very difficult to read. You should clean it up.

<table class="main" cellpadding="0" cellspacing="10" align="center">
    <tr>
        <td><h1>Base + Parts Dashboard</h1></td>
    </tr>
    <tr>
        <td><form name="partgen" action="index.php?i=99" method="post">
            <table class="quick" cellpadding="0" cellspacing="10" align="center" width="450">
                <tr>
                    <td colspan="3" valign="top"><h2>Parts Management</h2></td>
                </tr>
                    
                <tr>
                    <td valign="top">Select Base(s):</td>
                    <td><select class="drop" name="field[part_base_id][]" multiple="multiple" size="5">
                            <?=selectgen('base');?>
                        </select>
                    </td>
                    <td><input name="name[part_base_id]" type="hidden" value="Select Base(s)" /></td>
                </tr>
                <tr>
                    <td valign="top">Select Make(s):</td>
                    <td><select class="drop" name="field[part_make_id][]" multiple="multiple" size="5">
                            <?=selectgen('make');?>
                        </select>
                    </td>
                    <td><input name="name[part_make_id]" type="hidden" value="Select Make(s)" /></td>
                </tr>
                <tr>
                    <td>Kit Count:</td>
                    <td><input type="text" name="field[part_kit_count]" class="text"/></td>
                    <td><input name="name[part_kit_count]" type="hidden" value="Kit Count" /><b>i.e 2</b></td>
                </tr>
                <tr>
                    <td colspan="3" align="center"><input type="submit" name="submit" value="Submit" class="submit" /></td>
                </tr>
            </table>
            <input name="table" type="hidden" value="part" />
            <input name="key" type="hidden" value="part_id" />
            </form>
        </td>
    </tr>
</table>

Do a print_r on $_POST to see how it looks.

#3 micxnet

micxnet

    Newbie

  • Members
  • Pip
  • 6 posts
  • LocationAustralia

Posted 25 February 2006 - 11:22 PM

Here is what is outputted with the changes:

Array ( [part_base_id] => Array ( [0] => 123 ) [part_make_id] => Array ( [0] => 1 [1] => 2 ) [part_kit_count] => 1 )

Compared to with the old code:

Array ( [part_base_id[] => 123 [part_make_id[] => 2 [part_kit_count] => 1 )

Thanks for the help. Its working exactly how I need it.

#4 hitman6003

hitman6003

    Advanced Member

  • Members
  • PipPipPip
  • 1,807 posts

Posted 25 February 2006 - 11:25 PM

Did you notice what I changed in your code? I didn't just clean it up for you.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com