In general, the situation is as follows. There are two forms; the first form allows the user to select the number of processes using the checkbox . The second allows the user to assign elements to each process using jquery-drag and jquery-drop . The problem is that after assigning elements for each process, I want to print the resulting elements, sorted for each process. The added feed is an example with only two lines of processes. After clicking the 'save' button, I get one line with the saved list, but I need it to be two different lines for each of the processes. Here is the code with the loop :

  <label><?php for($y=0;$y<$len;$y++) { echo "<div class='proc'> <pre>"; echo "Process: ".$proc[$y]." "; echo "People required: ".$num[$y]." "; echo "<span class='assigned' name='assigned[]' >People Assigned: </span><br /></pre>"; ?> <div class="procLeader"> <label>Leader:</label> <div class="ui-widget-content"> <div class="procleader"> <ol> <li class="placeholder" name="procleader[]" <?php if (isset($procleader)) echo 'value="'.$procleader.'"' ?>>Add Process Leader here</li> <input type="hidden" name="procleader[]" class="hiddenListInput3" /> </ol> </div> </div> </div> <div class="procChecker"> <label>Checker:</label> <div class="ui-widget-content"> <div class="procchecker"> <ol> <li class="placeholder" name="procchecker[]" <?php if (isset($procchecker)) echo 'value="'.$procchecker.'"' ?>>Add Process Checker here</li> <input type="hidden" name="procchecker[]" class="hiddenListInput4" /> </ol> </div> </div> </div> <div class="prodStuff"> <label>Stuff:</label> <div class="ui-widget-content"> <div class="prodstuff"> <ol> <li class="placeholder" name="prodstuff[]" <?php if (isset($prodstuff)) echo 'value="'.$prodstuff.'"' ?>>Add Stuff here</li> <input type="hidden" name="prodstuff[]" class="hiddenListInput5" /> </ol> </div> </div> </div> <?php echo "</div>"; } ?> </label> 
  • Try to rephrase your question. It is very difficult to understand what your problem is. "cycle of saved objects" - better say an array or a list of objects. - koks_rs
  • @Yevgeniy Bagackiy I read it several times, but I still did not understand anything ... Do you have a problem with what ?! With PHP. JavaScript, jQuery or jQueryUI ?! - XelaNimed
  • @koks_rs I apologize if I described the problem incomprehensibly. Corrected post, you can look again. - Yevgeniy Bagackiy
  • @XelaNimed I apologize if I described the problem incomprehensibly. Corrected post, you can look again. - Yevgeniy Bagackiy

1 answer 1

In my opinion, you need to rewrite your code, but this is my personal opinion, which may not coincide with the harsh reality. Specifically on the topic:

  var LISTOBJ = { saveList: function() { // Выбираем все элементы с классом "proc" и проходим по ним циклом. $(".proc").each(function() { // В этот массив будем помещать текст из li-элементов. // Массив будет "заново" создаваться в каждой иттерации, // тем самым можно разделить значения каждого обрабатываемого // элемента "proc". var listCSV = []; // В текущем элементе "proc" выбираем все li-элементы // и проходим по ним циклом. $(this).find("li").each(function(){ // Добавляем в listCSV текст из текущего li-элемента. listCSV.push($(this).text()); }); // Преобразуем массив в строку вида "elem1","elem2","elem3" var values = '"'+listCSV.join('","')+'"'; // Добавляем в элемент с классом "procChecker" скрытый элемент ввода. // Kвадратные скобки в его имени указывают на авто.создание массива // на стороне сервера. Пример: http://stackoverflow.com/a/7880656/3129992 $(".procChecker").append("<input type='hidden' name='prodstuff[]' value='+values+' />"); // Вывод тестовых сообщений $("#output").append("<p>"+values+"</p>"); console.debug(listCSV); }); } } 
  • Thanks for the advice, I'll take it into account and see what can be done. By topic, the function works, but I need to not only print, but also save the array, so I use <input type="hidden" name="leader[]" class="hiddenListInput" /> , and then $(".hiddenListInput").val(listCSV); To save the received data, after using your variant, only the latest data from the last line of the cycle is saved. How can this be fixed? Thank you - Yevgeniy Bagackiy
  • @YevgeniyBagackiy If I understand correctly, you are transferring data to the PHP server in hidden fields. If so, you can transfer hidden fields with the same name (for example, prodstuff[] ). These server-side fields are automatically converted to an array. Answer corrected. - XelaNimed
  • Thank you very much for your help. Everything works as it should, could you comment on the code for a more complete understanding. And what could be changed in my code? What's wrong with it? Thanks for the answer, and I apologize for the terrible code, not so much experience, I will try to do better. :) I can't do Upvote because I don't have enough reputation. Thank. - Yevgeniy Bagackiy
  • @YevgeniyBagackiy Don't get me wrong, but this resource is not intended for educational purposes or its use as a forum. If you have any basic questions regarding the work of PHP or JavaScript, then I advise you to register on thematic sites, such as php.su and javascript.ru . The above resources contain articles highlighting the most frequently asked questions of people starting to learn web programming. PS: add comments to the code now. - XelaNimed
  • Well thank you. - Yevgeniy Bagackiy