form $_POST error, dynamic fields

luc79

New Member
I have an error that I can't figure out...Om my webpage there is a form that the user has the ability to add some new input fields to. If the user is submitting the form, then the optional fields is empty when the php-file is handing them, why?HTML:\[code\] <form method="post" action="newRequest.php"> <input type="text" name="title" /> <input type="hidden" name="fname" value="http://stackoverflow.com/questions/15525023/0" /> <input type="checkbox" name="fname" value="http://stackoverflow.com/questions/15525023/1"/> <input type="hidden" name="ename" value="http://stackoverflow.com/questions/15525023/0" /> <input type="checkbox" name="ename" value="http://stackoverflow.com/questions/15525023/1" /> <input type="hidden" name="seat" value="http://stackoverflow.com/questions/15525023/0" /> <input type="checkbox" name="seat" value="http://stackoverflow.com/questions/15525023/1" /> <input type="hidden" name="fields" value="http://stackoverflow.com/questions/15525023/0" /> <input type="text" id="fields" name="fields" /> <input type="submit" /> </form>\[/code\]PHP:\[code\]if (strlen($_POST[title]) > 2) { $toDb[title] = $_POST[title];} else { error('title');}$toDb[fname] = $_POST[fname];$toDb[ename] = $_POST[ename];$toDb[seat] = $_POST[seat];if ($_POST[fields] > 0) { $i = 0; while ($i < $_POST[fields]) { $toDb[optional][$i] = $_POST[optional-$i]; $i++; } $toDb[optional] = serialize($toDb[optional]);} else { $toDb[optional] = 0;}newEvent($toDb,$dbh);\[/code\]JQuery that is adding dynamical fields:\[code\]$(document).ready(function() { $('#fields').focusout(function(){ var fields = $('#fields').val(); var i = 0; while(i < fields) { $('#fields').after("Valfritt f?lt "+(i+1)+":<input type='text' name='optional"+i+"' />"); i++; } })})\[/code\]
 
Back
Top