siric Posted August 30, 2011 Share Posted August 30, 2011 Hi, I have a dynamic form which uses javascript to add rows on the fly. The name of the element on my test page is txtRow1, txtRow2, etc; the number is added when I add a new row. I am trying to figure out how I will extract the data once the form had been POSTED. I have tried $tags = $_POST['txtRow']; foreach ($tags as $t) { echo "$t<br />"; } but that shows nothing. I would be grateful for any assistance. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/245994-submitting-data-from-dynamic-form/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 30, 2011 Share Posted August 30, 2011 I recommend that you use an array for the form field name, with the 1,2,3,... as the array index txtRow[1], txtRow[2], txtRow[3]. Then your php code will be able to iterate over the data. Quote Link to comment https://forums.phpfreaks.com/topic/245994-submitting-data-from-dynamic-form/#findComment-1263356 Share on other sites More sharing options...
siric Posted August 30, 2011 Author Share Posted August 30, 2011 This is where the field name is defined in the javascript // Last updated 2006-02-21 function addRowToTable() { var tbl = document.getElementById('tblSample'); var lastRow = tbl.rows.length; // if there's no header row in the table, then iteration = lastRow + 1 var iteration = lastRow; var row = tbl.insertRow(lastRow); // left cell var cellLeft = row.insertCell(0); var textNode = document.createTextNode(iteration); cellLeft.appendChild(textNode); // right cell var cellRight = row.insertCell(1); var el = document.createElement('input'); el.type = 'text'; el.name = 'txtRow' + iteration; el.id = 'txtRow' + iteration; el.size = 40; How would I then define it as an array? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/245994-submitting-data-from-dynamic-form/#findComment-1263376 Share on other sites More sharing options...
PFMaBiSmAd Posted August 30, 2011 Share Posted August 30, 2011 el.name = 'txtRow[' + iteration + ']'; Quote Link to comment https://forums.phpfreaks.com/topic/245994-submitting-data-from-dynamic-form/#findComment-1263380 Share on other sites More sharing options...
siric Posted September 13, 2011 Author Share Posted September 13, 2011 Sorry to take so long to respond, but that worked. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/245994-submitting-data-from-dynamic-form/#findComment-1268681 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.