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.