nostrodamned Posted February 3, 2009 Share Posted February 3, 2009 Hi all, I have a form which creates checkboxes dynamically. This is the code for the checkbox generation <div class="column"> <?php $dir = "pdfs/"; $dh = opendir($dir); echo $file; $tindex="-2"; while (($file = readdir($dh)) !== false) { $tindex++; if($file=='.') continue; if($file=='..') continue; echo "<input id=\"id_$file\" name=\"name_$file\" type=\"checkbox\" class=\"field checkbox\" value=\"$file\" tabindex=\"$tindex\" checked=\"checked\" /> <label class=\"choice\" for=\"Field101\">$file</label> "; } closedir($dh); ?> </div> So what i need to do now is somehow on the page (processfiles.php - defined in the form action)that the gets the post values is something like this i used $file in each of the parameters - but thats not really necessary I just need the $file as the value of the checkbox that gets posted. For each checkbox value start processing this code then when done bounce back to the form page with with a url value processing=done. Does that make any sort of sense!! Quote Link to comment https://forums.phpfreaks.com/topic/143626-solved-dynamic-form-posting-values-for-processing/ Share on other sites More sharing options...
JonnoTheDev Posted February 3, 2009 Share Posted February 3, 2009 use an array as the checkbox name i.e. <input name="items[]" type="checkbox" Then in your processing you can loop through the array and process the values. Quote Link to comment https://forums.phpfreaks.com/topic/143626-solved-dynamic-form-posting-values-for-processing/#findComment-753628 Share on other sites More sharing options...
nostrodamned Posted February 3, 2009 Author Share Posted February 3, 2009 Hi I tried changing that but it just output the [] and didnt create an array value? and what would i do on the processing page - can you give me a code hint please!! Thanks nostro Quote Link to comment https://forums.phpfreaks.com/topic/143626-solved-dynamic-form-posting-values-for-processing/#findComment-753633 Share on other sites More sharing options...
JonnoTheDev Posted February 3, 2009 Share Posted February 3, 2009 You must be doing it wrong. Example <input name="items[]" type="checkbox" value="1" /> <input name="items[]" type="checkbox" value="2" /> <input name="items[]" type="checkbox" value="3" /> // Processing part foreach($_POST['items'] as $item) { // do something with the selected item } Quote Link to comment https://forums.phpfreaks.com/topic/143626-solved-dynamic-form-posting-values-for-processing/#findComment-753642 Share on other sites More sharing options...
nostrodamned Posted February 3, 2009 Author Share Posted February 3, 2009 oh sorry so the outputted html should be <input name="items[]" type="checkbox" value="3" /> not items[1] or something like that? I will give it a go! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/143626-solved-dynamic-form-posting-values-for-processing/#findComment-753663 Share on other sites More sharing options...
JonnoTheDev Posted February 3, 2009 Share Posted February 3, 2009 Correct. Quote Link to comment https://forums.phpfreaks.com/topic/143626-solved-dynamic-form-posting-values-for-processing/#findComment-753674 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.