I have a form that I created with rows of input fields that are created dynamically.
foreach ($data as $k => $v){
print "<tr>Table # $k</tr>";
print "<tr><td>First Name</td><td>Last Name</td></tr>"
for($i = 1; $i <= $data[$k]['tickets']; $i++){
print "<tr><td><input name='fname[]' type='text' class='mid_text_data' value=".$prefill[$k]['first_name']." maxlength='15' /></td><td><input name='lname[]' type='text' class='mid_text_data' value=".$prefill[$k]['last_name']." maxlength='15' /></tr>";
}
}
I've created the input fields based on the number of 'tickets' in my $data array, but I would like to prefill the values of fname with $prefill[$k]['first_name'].
My $prefill and $data variables look like:
$prefill = {
[145]=> array(9) {
["first_name"]=> string(5) "John"
["last_name"]=> string(6) "Doe"
["company"]=> string(10) "Big Business"
["email"]=> string(21) "[email protected]"
["photo_op"]=> int(0)
["gala"]=> int(1)
["chairman"]=> int(0)
["prefix"]=> NULL
["table_number"]=>int(60)
}
[146]=> array(9) {
["first_name"]=> string(5) "Jane"
["last_name"]=> string(6) "Doe"
["company"]=> string(10) "Big Business"
["email"]=> string(21) "[email protected]"
["photo_op"]=> int(0)
["gala"]=> int(1)
["chairman"]=> int(0)
["prefix"]=> NULL
["table_number"]=>int(60)
}
[147]=> array(9) {
["first_name"]=> string(5) "Stan"
["last_name"]=> string(6) "Derp"
["company"]=> string(10) "Big Business"
["email"]=> string(21) "[email protected]"
["photo_op"]=> int(0)
["gala"]=> int(1)
["chairman"]=> int(0)
["prefix"]=> NULL
["table_number"]=>int(83)
}
}
$data = {
[60]=> array(5) {
["tickets"]=> int(10)
["gala"]=> int(8)
["chair"]=> int(2)
["ind_id"]=> float(805879)
["photo"]=> int(0)
}
[83]=> array(5) {
["tickets"]=> int(5)
["gala"]=> int(5)
["chair"]=> NULL
["ind_id"]=> float(805879)
["photo"]=> int(1)
}
}
Currently, the form repeats 'John' to each one of my 'fname' fields.
Any ideas how to prefill the fields properly?
Thank you.
$data[$k]['tickets']can just be$v['tickets']in this case, for brevity.