admin管理员组文章数量:1401273
I have a category form.
<tbody>
<?php $no = 0;
foreach ($content as $row) : $no++; ?>
<tr>
<td><?= $no; ?></td>
<td><?= $row->title; ?></td>
<td><?= $row->slug; ?></td>
<td>
<?= form_open("category/delete/$row->categoryid", ['method' => 'POST']) ?>
<?= form_hidden('categoryid', $row->categoryid) ?>
<a href="<?= base_url("category/edit/$row->categoryid") ?>">
<button class="btn btn-sm">
<i class="fas fa-edit text-info"></i>
</button>
</a>
<button class="btn btn-sm"
type="submit"
onclick="return confirm('Are you sure?')">
<i class="fas fa-trash text-danger"></i>
</button>
<?= form_close() ?>
</td>
</tr>
<?php endforeach ?>
</tbody>
When I want to edit one of the items, it trigger delete button instead edit. but when I remove button tag in edit it works fine. please tell me where I went wrong
I have a category form.
<tbody>
<?php $no = 0;
foreach ($content as $row) : $no++; ?>
<tr>
<td><?= $no; ?></td>
<td><?= $row->title; ?></td>
<td><?= $row->slug; ?></td>
<td>
<?= form_open("category/delete/$row->categoryid", ['method' => 'POST']) ?>
<?= form_hidden('categoryid', $row->categoryid) ?>
<a href="<?= base_url("category/edit/$row->categoryid") ?>">
<button class="btn btn-sm">
<i class="fas fa-edit text-info"></i>
</button>
</a>
<button class="btn btn-sm"
type="submit"
onclick="return confirm('Are you sure?')">
<i class="fas fa-trash text-danger"></i>
</button>
<?= form_close() ?>
</td>
</tr>
<?php endforeach ?>
</tbody>
When I want to edit one of the items, it trigger delete button instead edit. but when I remove button tag in edit it works fine. please tell me where I went wrong
Share Improve this question edited Mar 23 at 7:25 marc_s 756k184 gold badges1.4k silver badges1.5k bronze badges asked Mar 23 at 5:00 crackerc0decrackerc0de 236 bronze badges 2- Never wrap a button in an A tag. Style the A as a button – mplungjan Commented Mar 23 at 9:07
- okay, thanks for your advice – crackerc0de Commented Mar 23 at 13:44
1 Answer
Reset to default 1The issue happens because you're wrapping the for editing inside an tag. When you click the button, the browser treats it as clicking the tag, and since tags don’t normally submit forms, the event propagates to the nearest with a type="submit"—which is your delete button.
<td>
<?= form_open("category/delete/$row->categoryid", ['method' => 'POST']) ?>
<?= form_hidden('categoryid', $row->categoryid) ?>
<a href="<?= base_url("category/edit/$row->categoryid") ?>" class="btn btn-sm">
<i class="fas fa-edit text-info"></i>
</a>
<button class="btn btn-sm" type="submit" onclick="return confirm('Are you sure?')">
<i class="fas fa-trash text-danger"></i>
</button>
<?= form_close() ?>
</td>
本文标签: Html a tag didn39t get what I clickStack Overflow
版权声明:本文标题:Html a tag didn't get what I click - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744296677a2599375.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论