我在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>
答案 0 :(得分:1)
type="button"
类型的编辑按钮,不要提交。POST
输入edit()
,传递广告系列
id为请求值。edit()
应该只负责获取
来自db的相应记录的详细信息以及返回呈现的form.tpl
内容(将详细信息传递给它)。success
回调内)并写入表单
容器(如<div class="form-container"></div>
)某处
campaign-table
列表之前,之内或之后。你可以改为定义一个
在每个记录中形成容器,让ajax填充一个
form.tpl内容,已发布的广告系列ID所属。updateButton
的提交按钮
(将value
属性中的广告系列ID)发送
表单字段的值 - 由用户完成 - 到控制器
名为update()
的行动。当然,会发送广告系列ID
太update()
操作将读取所有POST传递的值和
更新数据库中的记录。最后它应该重新发送
广告系列列表,有或没有表格 - 这取决于你,如何
你希望拥有它 - 重新显示,以及相应的“更新
成功/失败“消息。