Jump to content

HTML Form & Multi-Dimensional Arrays


micxnet

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.