Jump to content

Archived

This topic is now archived and is closed to further replies.

micxnet

HTML Form & Multi-Dimensional Arrays

Recommended Posts

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:

[code]
<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>
[/code]

Thanks in advance.

Share this post


Link to post
Share on other sites
Your html is very difficult to read. You should clean it up.

[code]
<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>
[/code]

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.