ntjimb Posted April 21, 2009 Share Posted April 21, 2009 I have a text file I am reading line by line and inserting into input fields. The names are unique because of the counter, verified in source. I ALSO need to have a way to Add fields on the fly once the page comes up with the ones from the file. The page works just great, but when i submit, only the input that was added with the JS is recognized. I get an undefined index error for the input that was generated by reading the file. The JS was pulled from http://www.programmingtalk.com/archive/index.php/t-%20%3C/t-36323.html and http://www.quirksmode.org/dom/domform.html. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <?php include("inc/head-tag.php"); //css and js includes?> <title>Asterisk Web Interface Dev</title> <script type="text/javascript"> <!-- var counter = 0; function init() { document.getElementById('moreFields').onclick = moreFields; moreFields(); } function moreFields() { document.getElementById('counterDisplay').innerHTML = counter + "."; var newFields = document.getElementById('readroot').cloneNode(true); newFields.id = ''; newFields.style.display = 'block'; var newField = newFields.childNodes; for (var i=0;i<newField.length;i++) { var theName = newField[i].name if (theName) newField[i].name = theName + counter; } var insertHere = document.getElementById('writeroot'); insertHere.parentNode.insertBefore(newFields,insertHere); counter++; } //window.onload = function (){moreFields();}; // --> </script> </head> <?php //----------- // START PAGE //----------- ?> <body> <?php include("inc/header.php"); ?> <div id="content"> <div class="container_12"> <div class="grid_12"> <table border="0" cellspacing="0" cellpadding="0"> <tr> <td class="title-lineCount"><!--blank--></td> <td class="title-mac">MAC / Serial#</td> <td class="title-dn">DN</td> <td>Model</td> <td><!--blank--></td> </tr> </table> <?php // READ FILE $file = fopen("DATA/newphones.txt", "r") or exit("Unable to open file!"); // Output a line of the file until the end is reached $lineCount = 1; while(!feof($file)) { echo '<div class="NEWPHONE" style="position: relative; padding: 4px 25px;">'; echo '<span>' . $lineCount . '.</span>'; //numbered echo '<input class="mac-locked" name="mac' . $lineCount . '" value="' . fgets($file) . '" type="text" readonly="readonly" /> '; //mac echo '<input class="dn" name="dn' . $lineCount . '" value="" type="text" /> '; //dn echo '<select name="model' . $lineCount . '"><option value="polycom1">Polycom1</option><option value="polycom2">Polycom2</option></select> '; echo '<input type="button" value="Remove" onclick="this.parentNode.parentNode.removeChild(this.parentNode);" />'; //remove echo '</div>'; $lineCount = $lineCount+1; } fclose($file); ?> <script type="text/javascript"> // Pass $lineCount to js var counter so when adding phone, the field names number sequence is correct counter = <?php echo $lineCount; ?>; </script> <div id="readroot" style="display: none; position: relative; padding: 4px 25px;"> <span id="counterDisplay"></span> <input class="mac" name="mac" value="" type="text" /> <input class="dn" name="dn" value="" type="text" /> <select name="model"> <option value="polycom1">Polycom1</option> <option value="polycom2">Polycom2</option> </select> <input type="button" value="Remove" onclick="this.parentNode.parentNode.removeChild(this.parentNode);" /> </div> <form method="post" action="ACTION.php"> <span id="writeroot"></span> <input type="button" id="btnMoreFields" onclick="moreFields();" value="Add Phone" /><br /><br /> <input type="submit" value="Submit" /> </form> </div> <div class="clear"> </div> </div> </div> </body> </html> and the action.php is simply <?php echo $_POST["mac1"]; echo $_POST["mac11"]; ?> mac1 errors, mac11 prints My guess is that the form only sees the JS part because of the script, but I don't really see why or know how to get around this. Image attached for a visual if needed. I know I would [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/155047-php-half-of-phpjs-form-submit-not-working/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.