Fórum Root.cz
		Hlavní témata => Vývoj => Téma založeno: MichalPecko89  15. 12. 2020, 13:40:37
		
			
			- 
				Zdar
 V kode je toto
  <form name="raise" action="index.php?go=forms/frm_new_fill.php" method="POST">
 
 <table id="tab_logic" style="background-color: #c0c0c0;text-align:center">
 <thead>
 <tr>
 <th scope="col">None</th>
 <th scope="col">Part number</th>
 <th scope="col">Location</th>
 <th scope="col">Quantity</th>
 <th scope="col">Reason</th>
 <th scope="col">Notes</th>
 
 </tr>
 </thead>
 <tbody>
 
 </tbody>
 </table>
 
 <div class="buttons">
 <button type="submit" name="new" class="positive" onClick="submitLoader();">
 <img src="Assets/images/apply2.png" width="16" height="16" alt=""/>
 Submit
 </button>
 </div><div name="submitLoader" id="submitLoader" style="float:left"></div>
 
 <div class="buttons">
 <button type="reset" name="new" class="negative">
 <img src="Assets/images/cross.png" width="16" height="16" alt=""/>
 Reset
 </button>
 </div>
 
 </form>
 
 s scripte toto
 
 <script>
 $(document).ready(function() {
 var i = 0;
 var j = 0;
 var code = '<?php give_me_reason_list();  ?>';
 
 
 
 
 $("#add_row").click(function() {
 $('tr').find('input').prop('disabled',true)
 j = i;
 
 $('#addr' + i).html(""+(j+1)+ "<td><input type='radio' name='plusminus" + j + "' id='plusminus" + j + "' value='1' onClick='activateReasons(" + j + ");' required/> +<BR/><input type='radio' name='plusminus" + j + "' id='plusminus" + j + "' value='2' onClick='activateReasons(" + j + ");'/>  -<input type='hidden' name='value" + j + " id='value" + j + "' value=''><input type='hidden' name='curr" + j + "' id='curr" + j + "' value=''><input type='hidden' name='converted" + j + "' value=''></td><td style='text-align:left'><input type='text' name='part_no" + j + "' id='part_no" + j + "' value='' onBlur='getDescription(" + j + ");' required/><br/><div id='description" + j + "' style='text-align:left'></div><div id='price" + j + "' style='text-align:left'></div><div id='gbp_price" + j + "' style='text-align:left'></div></td><td><select name='location" + j + "' id='location" + j + "'><option value='S001'>Main Warehouse</option><option value='S002'>Moulding</option><option value='S003'>Production</option><option value='S090'>Finished Goods</option></select></td><td><input type='number' step='0.01' name='qty" + j + "' id='qty" + j + "' value='' size='5' onBlur='getPrice(" + j + ");'/></td>'<td><select id='reason" + j + "' name='reason" + j + "' disabled onChange='getCodes(" + j + ");'>"+ code + "</select><br/><div name='gl_cc" + j + "' id='gl_cc" + j + "' style='text-align:left'>You must choose + or - to be able to select reason.</div></td><td><textarea name='notes" + j + "' rows=3 cols=20></textarea></td>" );
 j++
 $('#tab_logic').append('<tr id="addr' + (i + 1) + '"></tr>');
 document.getElementById("item_count").value= i;
 i++;
 });
 });
 </script>
 
 Ak odoslem len jednu polozku je to fajn. Ak ich odoslem 2 alebo viac take mi to hadze chybu otice: Undefined index: part_no1 in
 kod ktory to spracovava
 
 for ($j = 1; $j <= $i; $j++) {
 $clock_no = $_POST['clock_no'];
 $part_no = strtoupper($_POST['part_no' . $j . '']);
 echo $part_no;
 $qty = $_POST['qty' . $j . ''];
 $location = trim($_POST['location' . $j . '']);
 $reason = $_POST['reason' . $j . ''];
 $notes = $_POST['notes' . $j . ''];
 $notes = str_replace("'", "''", $notes);
 if (isset($_POST['gl_account' . $j . ''])) {
 $gl_account = $_POST['gl_account' . $j . ''];
 } else {
 $gl_account = '';
 }
 if (isset($_POST['cost_centre' . $j . ''])) {
 $cost_centre = $_POST['cost_centre' . $j . ''];
 } else {
 $cost_centre = '';
 }
- 
				Začal bych tímto:
 <?php
 var_dump($_POST);
Zpravidla to odpoví na všechny podobné otázky.
- 
				Kit ok
 Ak posielam jednu polozku je to fajn.
 array (size=12)
 'item_count' => string '1' (length=1)
 'clock_no' => string '1132' (length=4)
 'plusminus1' => string '1' (length=1)
 'value1_id=' => string '' (length=0)
 'curr1' => string 'EUR' (length=3)
 'converted1' => string '' (length=0)
 'part_no1' => string 'ewre' (length=4)
 'location1' => string 'S001' (length=4)
 'qty1' => string '555' (length=3)
 'reason1' => string 'Stock Discrepancy' (length=17)
 'notes1' => string '' (length=0)
 'new' => string '' (length=0)
toto je ked posielam 2
 array (size=15)
 'item_count' => string '2' (length=1)
 'clock_no' => string '1132' (length=4)
 'location1' => string 'S002' (length=4)
 'reason1' => string 'Stock Check Errors' (length=18)
 'notes1' => string '' (length=0)
 'plusminus2' => string '1' (length=1)
 'value2_id=' => string '' (length=0)
 'curr2' => string 'EUR' (length=3)
 'converted2' => string '' (length=0)
 'part_no2' => string '52' (length=2)
 'location2' => string 'S001' (length=4)
 'qty2' => string '25' (length=2)
 'reason2' => string 'Free Issue' (length=10)
 'notes2' => string '' (length=0)
 'new' => string '' (length=0)
Ked posielam 2  a viac tak sa stratia parametre s pevej ako je to mozne ked je to rovnaky kod? Ved je to uplne jednoduchy kusok kodu.
 
- 
				Zřejmě si ten form přepisuješ. Koukám, že tam máš dvakrát id="plusminus".
			
- 
				Proč tam máš tohle?
 for ($j = 1; ...Obvykle používám foreach nebo aspoň počítám od nuly.
- 
				Skusam oboje ale zda sa mi ze mi to vzdy ako keby odsekne prve data. Netusim preco. 
 Nepoviem keby to nefunguje s jednym ale ten da v poriadku, uz ked su dva tak to nejde.
 vzdy zmizne
 'plusminus1' => string '1' (length=1)
 'value1_id=' => string '' (length=0)
 'curr1' => string 'EUR' (length=3)
 'converted1' => string '' (length=0)
 'part_no1' => string 'ewre' (length=4)
 ten var_dump($_POST); som dal na zaciatok este pred for loop
- 
				Zmenil som jednu jedinu vec a ide to
 $('tr').find('input').prop('disabled',false)ale netusim co je pricina.
- 
				No jasně. Tímto příkazem jsi vždy odstavil předchozí input.