HI All,

I have a small question regarding forms in php, and adding them to an array.

<table><tr>													
<td style="width:130px;" valign="middle" align="left" class="profile_link">
<input type="checkbox" name="suitwearing[]" value="HR Director" />&nbsp;HR Director
</td>
</tr>
<tr>
<td style="width:130px;" valign="middle" align="left" class="profile_link">Other
<input type="text" name="????" value="????" style="border:1px #E3A538 solid; width:100px; height:20px" />
</td>
</tr>
</table>

What I am trying to do here, is create an array of checkbox values, and than add the "other" textfield into this array.

Any tips?
Appreciate your help!

Hi,

How about:

<div class="field">
    <input id="suitwearning" type="checkbox" name="suitwearing[]" value="HR Director">
    <label for="suitwearing">HR Director</label>
</div>

<div class="field">
    <label for="other">Other</label>
    <input id="other" type="text" name="suitwearing[other]" value="Sales Assistant" />
</div>

Then when the form is submitted you can access the data like so:

$data = $_POST['suitwearing'];

foreach($data as $field => $value) {
    echo "{$field}: {$value}\n";
}

// 0: HR Director    - if checked
// other: Sales Assistant

Hope this helps.
R.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.