0
我在OpenCart中工作,並有一個列表和一個表單.tpl一起工作,表單創建新記錄,並且信息顯示在列表中。該列表給出了每個記錄的選項(編輯,刪除,存檔)我試圖讓編輯功能工作。當單擊編輯特定行時,我希望顯示的表單中已經填入了現有信息的輸入。然後可以由用戶更新。目前發生的情況是,單擊編輯時它不會啓動表單,而是編輯當前記錄,但是具有零和空列。我不知道如何重新啓動表單。並顯示用戶的信息更新動態填充列表中的記錄
型號:
public function editCampaign($campaign_id, $data) {
$this->db->query("UPDATE " . DB_PREFIX . "campaigns SET campaign_name = '" . $this->db->escape($data['campaign_name']) . "', campaign_giving_goal = '" . (float)$data['campaign_giving_goal'] . "', campaign_giving_count_goal = '" . (float)$data['campaign_giving_count_goal'] . "', campaign_owner = '" . $data['campaign_owner'] . "', date_beginning = '" . $this->db->escape($data['date_beginning']) . "', date_ending = '" . $this->db->escape($data['date_ending']) ."' WHERE campaign_id = '" . (int)$campaign_id . "'");
}
控制器:
public function edit() {
$this->load->language('campaigns/campaign');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('campaigns/campaign');
if (isset($this->request->post['editButton'])) {
$campaign_id = $this->request->post['editButton'];
$this->model_campaigns_campaign->editCampaign($campaign_id);
$this->session->data['success'] = $this->language->get('text_success');
$this->response->redirect($this->url->link('campaigns/campaign', 'token=' . $this->session->data['token'] . $url, true));
}
$this->getForm();
}
檢視:
<form method="post" action="" enctype="multipart/form-data" id="form-order">
<div class="table-responsive">
<table class="table" id="campaign-table">
<thead>
<tr>
<td><?php echo $column_campaign_id; ?></td>
<td><?php echo $column_campaign; ?></td>
<td><?php echo $column_giving_goal; ?></td>
<td><?php echo $column_giving_count_goal; ?></td>
<td><?php echo $column_owner; ?></td>
<td></td>
</tr>
</thead>
<tbody>
<?php if ($orders) { ?>
<?php foreach ($orders as $order) { ?>
<tr class="campaign-list">
<td><?php echo $order['campaign_id']; ?></td>
<td><?php echo $order['campaign_name']; ?></td>
<td><?php echo $order['campaign_giving_goal']; ?></td>
<td><?php echo $order['campaign_giving_count_goal']; ?></td>
<td><?php echo $order['campaign_owner']; ?></td>
<td>
<div class="dropdown">
<button class="campaign-dropdown-btn dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"><?php echo $text_campaign_dropdown;?><span class="caret"></span></button>
<ul class="campaign-list-more dropdown-menu">
<li class="campaign-dropdown-list"><button type="submit" id="campaign-del" name="editButton" value="<?php echo $order['campaign_id']; ?>" onclick="javascript:changeFormAction('<?php echo $edit; ?>');">
<?php echo $button_edit; ?>
</button></li>
<li class="campaign-dropdown-list">Archive</li>
<li class="campaign-dropdown-list">
<button type="submit" id="campaign-del" name="deleteButton" value="<?php echo $order['campaign_id']; ?>" onclick="javascript:changeFormAction('<?php echo $delete; ?>');">
<?php echo $button_delete; ?>
</button>
</li>
</ul>
</div>
</td>
</tr>
<?php } ?>
<?php } else { ?>
<tr>
<td class="text-center" colspan="8"><?php echo $text_no_results; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</form>
JS:
<script type="text/javascript">
function changeFormAction(action) {
var form = document.getElementById('form-order');
form.action = action;
return true;
}
</script>