Please look at the picture
I want to post all the fields data to a specific controller when pressed in confirm order. And then want to add these to database.
I can't get the data from all fields. As it's a loop genereated fields. I placed the id's of each medicine in for each fields. But how can I post these all to a controller function and from the controller function i can receive those data and put into database?
I get the table from another php file. And the buttons are in another php file. so the confirm button and the table and fields are not from same php page.
here is the code:
<div class="row-fluid">
<div class="span8">
<div class="widget">
<div class="widget-header">
<div class="title">
<span class="fs1" aria-hidden="true" data-icon=""></span> Short Quantity List from current stock....
</div>
</div>
<div class="widget-body">
<form class="form-horizontal no-margin" action="<?php echo site_url('order/queue')?>" method="post">
<table class="table table-bordered" id="myTableDot">
<thead>
<tr>
<?php if($flag == "noprint") { ?>
<th class="center-align-text" style="width:9%; border: 1px solid #000;"><input id="select-all" type="checkbox" /></th>
<?php } ?>
<th style="width:17%; border: 1px solid #000;">Supplier</th>
<th style="width:15%; border: 1px solid #000;">Name</th>
<th class="hidden-phone center-align-text" style="width: 8%; border: 1px solid #000;">Order</th>
<th class="hidden-phone center-align-text" style="width: 7%; border: 1px solid #000;">Min Qty</th>
<th class="hidden-phone center-align-text" style="width: 8%; border: 1px solid #000;">Box Qty</th>
<th class="hidden-phone center-align-text" style="width: 8%; border: 1px solid #000;">In Stock</th>
</tr>
</thead>
<tbody id="shortqtytable"> <?php } ?>
<?php //if($flag == "noprint") { ?>
<!-- <tr>
<td colspan="8"><button type="submit" class="btn btn-mini btn-success pull-right">Add to Order</button></td>
</tr>-->
<?php //} ?>
<?php if($meds != FALSE){foreach ($meds->result() as $med) { { ?>
<tr>
<?php //if($flag == "noprint") { ?>
<!-- <td style="width:5%;text-align:center;border: 1px solid #000;"><input type="checkbox" name="mid[]" value="<?php //echo $med->id; ?>" /></td>-->
<?php //} ?>
<td style="border-top: 1px solid #000; border-left: 1px solid #000;"><?php echo $med->Supplier; ?></td>
<td style="border-top: 1px solid #000; border-left: 1px solid #000;"><?php echo $med->name; ?></td>
<td style="text-align: center; border-top: 1px solid #000; border-left: 1px solid #000; border-right: 1px solid #000;">
<b>
<form class="form-horizontal no-margin" action="<?php echo site_url('medicine/add_order'); ?>" method="post" id="raiseForm">
<!-- <input type="text" name="stockqty" value="<?php //echo $med->name; ?>"></b> -->
<input type="number" name="<?php echo $med->name; ?>"></b>
<!-- <input type="hidden" name="trigger" value="addstock" /> -->
<input type="hidden" name="name2" value="<?php echo $med->name; ?>"/>
</form>
</td>
<td style="text-align: center; border-top: 1px solid #000; border-left: 1px solid #000;"><?php echo $med->minqty; ?></td>
<td style="text-align: center; border-top: 1px solid #000; border-left: 1px solid #000;"><?php echo $med->boxqty; ?></td>
<td style="text-align: center; border-top: 1px solid #000; border-left: 1px solid #000; border-right: 1px solid #000;"><b><?php echo $med->m_stok; ?></b></td>
<?php //if($flag == "noprint") { ?>
<!-- <td class="center-align-text" style="border: 1px solid #000;">
<div class="label label-important">Short</div>
</td>-->
<?php //} ?>
</tr>
<?php } } } ?>
<?php if($flag == "print") { ?>
</tbody>
</table>
<div class="clearfix"></div>
<input type="hidden" name="rebounce" value="medicine/shortqty" />
</form>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
你的问题在于foreach的每次迭代都有一个新的<form>
,这意味着如果你提交表单,就会出现问题并且你不会获得所有字段。你已经有一个<div class="row-fluid">
<div class="span8">
<div class="widget">
<div class="widget-header">
<div class="title">
<span class="fs1" aria-hidden="true" data-icon=""></span> Short Quantity List from current stock....
</div>
</div>
<div class="widget-body">
<form class="form-horizontal no-margin" action="<?php echo site_url('some_controller/process') ?>" method="post">
<table class="table table-bordered" id="myTableDot">
<thead>
<tr>
<th class="center-align-text" style="width:9%; border: 1px solid #000;"><input id="select-all" type="checkbox" /></th>
<th style="width:17%; border: 1px solid #000;">Supplier</th>
<th style="width:15%; border: 1px solid #000;">Name</th>
<th class="hidden-phone center-align-text" style="width: 8%; border: 1px solid #000;">Order</th>
<th class="hidden-phone center-align-text" style="width: 7%; border: 1px solid #000;">Min Qty</th>
<th class="hidden-phone center-align-text" style="width: 8%; border: 1px solid #000;">Box Qty</th>
<th class="hidden-phone center-align-text" style="width: 8%; border: 1px solid #000;">In Stock</th>
</tr>
</thead>
<tbody id="shortqtytable">
<?php foreach ($meds->result() as $med) { ?>
<tr>
<td style="border-top: 1px solid #000; border-left: 1px solid #000;"><?php echo $med->Supplier; ?></td>
<td style="border-top: 1px solid #000; border-left: 1px solid #000;"><?php echo $med->name; ?></td>
<td style="text-align: center; border-top: 1px solid #000; border-left: 1px solid #000; border-right: 1px solid #000;">
<input type="number" name="<?php echo $med->name; ?>"></b>
<input type="hidden" name="name2" value="<?php echo $med->name; ?>"/>
</td>
<td style="text-align: center; border-top: 1px solid #000; border-left: 1px solid #000;"><?php echo $med->minqty; ?></td>
<td style="text-align: center; border-top: 1px solid #000; border-left: 1px solid #000;"><?php echo $med->boxqty; ?></td>
<td style="text-align: center; border-top: 1px solid #000; border-left: 1px solid #000; border-right: 1px solid #000;"><b><?php echo $med->m_stok; ?></b></td>
</tr>
<?php } ?>
</tbody>
</table>
<div class="clearfix"></div>
<input type="hidden" name="rebounce" value="medicine/shortqty" />
<input type="submit" name="submit" value="Submit form">
</form>
</div>
</div>
</div>
</div>
包装器,它是正确的位置(我不知道它的作用),但你可以使用它来提交,因为它将包含你需要的所有输入。
<?php
class Some_controller extends CI_Controller {
public function process() {
print_r($_POST);
}
}
?>
控制器:
</form>
您还需要我在$_POST
标记之前添加的提交输入。
你也可以直接使用semaphore
数组,因为数组键是字段的名称,值是订单数量。