0

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!

2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by blocblue
0

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.

Edited by blocblue: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.