Dynamically added text fields passed to PHP script

If I am posting this to the wrong section please move it somewhere it fits. I apologize if this is not the correct section.

I have a site where I want to have form that in a "Visitor name" section to be able to add fieldets as needed. I think I have that worked out.

So the below code is the text area boxes. There is a First Name, Last Name and a Job Title field.

    <fieldset>
            <legend>Visitor Name</legend>
    <div id="placeholder">
            <div id="addmore">
                    <label for="firstname">First Name:</label>
                    <input type="text" name="name[]" value="">
                    <label for="lastname">Last Name:</label>
                    <input type="text" name="name[]" value"">
                    <label for="jobtitle">Job Title:</label>
                    <input type="text" name="name[]" value="">
            </div>
    </div>

and the js code to recreate the fieldset is

    var _counter = 0;
    function Add() {
        _counter++;
        var oClone = document.getElementById("addmore").cloneNode(true);
        oClone.id += (_counter + "");
        document.getElementById("placeholder").appendChild(oClone);
    }

That creates the fields when the "Add Visitor" button is pushed with no limit to the amount of dynamic fileds that can be created. It basically just copies the fieldset.

So I guess the PHP part is where I am getting hung up.

How do I pass those dynamic values into the php script and place them in a file.

When I use

    foreach($_POST['name'] as $info) {
          fwrite($file, "$some other form data,$info,some other form data \n");
        }

I get

Company,Fred,No,No,No,No,Yes,No,No,No,No,Yes,No,Yes
Company,Williams,No,No,No,No,Yes,No,No,No,No,Yes,No,Yes
Company,Hello,No,No,No,No,Yes,No,No,No,No,Yes,No,Yes
Company,Todd,No,No,No,No,Yes,No,No,No,No,Yes,No,Yes
Company,Williams,No,No,No,No,Yes,No,No,No,No,Yes,No,Yes
Company,Hello,No,No,No,No,Yes,No,No,No,No,Yes,No,Yes

Instead of

Company,Fred,Williams,Hello,No,No,No,No,Yes,No,No,No,No,Yes,No,Yes
Company,Todd,Williams,Hello,No,No,No,No,Yes,No,No,No,No,Yes,No,Yes

So I guess I am getting the data but I need it put in the above format. I assume that it is adding a line for each entry of the name $_POST.

Sorry for my ignorance on this.

when I do:

    $my_array = $_POST['name'];
    $visitor = implode(",",$my_array);

and then

    echo "$some other form data,$visitor,some other form data <br />";

and have more than one name it give me

Company,Billy,Williams,test,Bobby,Williams,test,No,No,No,No,No,No,No,No,No,No,No,No

to which I get that is is just taking the $visitor array and adding to the $visitor section. So it is getting the data I just still can't get it in a file one line per name.

and when I do

    print_r($visitor);

I get the information that was entered into the text boxes in one line.

Billy,Williams,test,Bob,Williams,test

and when I do

print_r($_POST);

I get

Array ( [companyname] => Buster [name] => Array ( [0] => bob [1] => Buddy [2] => Test [3] => bob [4] => Buddy [5] => Test ) [Submit] => Add Visitor )

So as of now I am stuck. I tried to search the forum and did not find anything, so if there is a post please point me in that direction.

Thanks in advance for your help.

So they are stored as names boxes1...boxesn? You could do a while-loop, checking whether each column exists in POST, adding to the end of a string each time. Then the rest of the fields once that's done.

well

$boxes,$boxes1,$boxes2,$boxes3,$boxes4,$boxes5,$boxes6,$boxes7,$boxes8,$boxes9,$boxes10,$boxes11

is other data in the form.

I feel like I am misunderstanding your suggestion.

I should have left the boxes out of the post so not to confuse the subject. I will edit the original post.

So you have a dozen textboxes with the exact same title?

Just three until the copying of the fieldsets

 
<fieldset>
            <legend>Visitor Name</legend>
    <div id="placeholder">
            <div id="addmore">
                    <label for="firstname">First Name:</label>
                    <input type="text" name="name[]" value="">
                    <label for="lastname">Last Name:</label>
                    <input type="text" name="name[]" value"">
                    <label for="jobtitle">Job Title:</label>
                    <input type="text" name="name[]" value="">
            </div>
    </div>
</fieldset>

There is no limit to how many times the fieldset can be copied.

---------- Post updated at 10:18 PM ---------- Previous update was at 09:38 PM ----------

Ok I got this to do what I wanted to do. Here is the code I used

 
foreach($firstname as $key => $value){
fwrite($file, "$companyname,$value,$lastname[$key],$jobtitle[$key],$boxes,$boxes1,$boxes2,$boxes3,$boxes4,$boxes5,$boxes6,$boxes7,$boxes8,$boxes9,$boxes10,$boxes11 \n");

My output file now looks like

 
Company,FirstName,Lastname,JobTitle,ProcessCenter,Receiving,Warehouse,DigitalPrint,Bindery,Mailing,Picking,QualityControl,Packing,Collation,Shipping,ClientServices
Company,FirstName,Lastname,Print,No,No,No,No,No,No,No,No,No,No,No,No
Company,FirstName,Lastname,Print,No,No,No,No,No,No,No,No,No,No,No,No
Company,FirstName,Lastname,Print,No,No,No,No,No,No,No,No,No,No,No,No