I am trying to store data from dynamically created fields using PhP. The fixed fields are not a problem. I am having toubles in GET-ing the "flex"fields. That is: the fields a user can generated (till the max of 3) to add moren participants for an event. I have searched this site, the internet in general and studied the PhP manual.It seems as if the solutions lies in working with foreach, but I am not smart and skilled enough (yet) to compose the right Function.
The code I came up to so far (work in progress) is:
HTML
var counter = 0; var limit = 3; var veldwaarde ="";
function addInput(divName){
if (counter == limit) { alert("More then " + counter + " partcipants not possible "); } else { var newdiv = document.createElement('div'); newdiv.innerHTML = "<table><tr><td>Naam deelnemer " + (counter + 1)
" " >+" Schoenmaat deelnemer " + (counter+ 1) +"
Naam:id="naam" value="" > Schoenmaat: >id="schoenmaat" value="" > Adres:value="" > Postcode:id="postcode" value="" > Woonplaats:id="woonplaats" value="" > E-mail:value="" > Telefoon overdag:id="telefoon" value=""> --> More partcipants: onClick="addInput('dynamicInput');return false;">Add (max 3) >partcipants
type='text' name='myInputs2[]'>";
document.getElementById(divName).appendChild(newdiv); counter++; } }
PhP
// Validation if (strlen($naam) == 0 ) { die("First > field is empty
"); }//saving record in a text file to test the GET function $pfw_file_name = "invoerDynvelden.txt"; $pfw_first_raw =
"naam,schoenmaat,adres,postcode,woonplaats,email,telefoon,naam2,schoenmaat2,naam3,schoenma> at3,naam4,schoenmaat4\r\n"; $pfw_values = "$naam,$schoenmaat,$adres,$postcode,$woonplaats,$email,$telefoon,$naam2,$schoenmaat2,$naam> 3,$schoenmaat3,$naam4,$schoenmaat4\r\n"; $pfw_is_first_row = false; if(!file_exists($pfw_file_name)) { $pfw_is_first_row = true ; } if (!$pfw_handle = fopen($pfw_file_name, 'a+')) { die("Cannot open file ($pfw_file_name)"); exit; } if ($pfw_is_first_row) { if (fwrite($pfw_handle, $pfw_first_raw ) === FALSE) { die("Cannot write to file ($pfw_filename)"); exit; } } if (fwrite($pfw_handle, $pfw_values) === FALSE) { die("Cannot write to file ($pfw_filename)"); exit; } fclose($pfw_handle); //saving record to MySQL database DBxxxxx still to be developped ?> Returm to entry screen