Write dynamic form data to its own line in a file
<hr>

<p>Well I will start over on what I am trying to accomplish.</p>

<p>I have a site where I want to have form that in a "Visitor name" section to be able to add fields as needed. I think I have that worked out.</p>

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

<p>and the js code is</p>

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

<p>That creates the fields when the "Add Visitor" button is pushed with no limit to the amount of dynamic fileds that can be created.</p>

<p>So I guess the PHP part is where I am getting hung up.</p>

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

<p>When I use</p>

<pre><code>foreach($_POST['name'] as $info) {
      fwrite($file, "$companyname,$info,$boxes,$boxes1,$boxes2,$boxes3,$boxes4,$boxes5,$boxes6,$boxes7,$boxes8,$boxes9,$boxes10,$boxes11 \n");
    }
</code></pre>

<p>I get</p>

<p>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</p>

<p>Instead of</p>

<p>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</p>

<p>So I guess I am getting the data but I need it put in the above format.</p>

<p>Sorry for my ignorance on this.</p>

<p>when I do:</p>

<pre><code>$my_array = $_POST['name'];
$visitor = implode(",",$my_array);
</code></pre>

<p>and then</p>

<pre><code>echo "$companyname,$visitor,$boxes,$boxes1,$boxes2,$boxes3,$boxes4,$boxes5,$boxes6,$boxes7,$boxes8,$boxes9,$boxes10,$boxes11 &lt;br /&gt;";
</code></pre>

<p>and have more than one name it give me</p>

<p>Company,Billy,Williams,test,Bobby,Williams,test,No,No,No,No,No,No,No,No,No,No,No,No</p>

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

<p>and when I do</p>

<pre><code>print_r($visitor);
</code></pre>

<p>I get the information that was entered into the text boxes in one line.</p>

<p>Billy,Williams,test,Bob,Williams,test</p>

<p>and when I do</p>

<pre><code>print_r($_POST);
</code></pre>

<p>I get</p>

<pre><code>Array ( [companyname] =&gt; Buster [name] =&gt; Array ( [0] =&gt; bob [1] =&gt; Buddy [2] =&gt; Test [3] =&gt; bob [4] =&gt; Buddy [5] =&gt; Test ) [Submit] =&gt; Add Visitor )
</code></pre>

<p>I figured this out.</p>

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