我想要做的很简单:我想使用Code Igniter的表单助手创建一个表单,并在表单中放置其他按钮(除了提交按钮)。让我来说明使用这个片段(不是我的实际形式):
<?php echo form_open('client/send_message'); ?>
<input type="text" name="message" required />
<button class="btn btn-primary btn-block">Send</button>
<button class="btn btn-default btn-block" data-toggle="modal" data-target="#my_modal">Send Email</button>
<?php echo form_close(); ?>
第二个按钮发送电子邮件应该打开一个模式。问题是这样,点击发送电子邮件按钮也会处理表单。所以看起来你在同一个表单中不能有多个按钮。我知道我可以在表单外部使用“发送电子邮件”按钮,但我的原始表单在表单中的不同位置有几个按钮,将它们放在表单之外会破坏设计。我也知道我可以在表单中使用<input type="button">
,但我真的想知道这种行为的原因以及是否有解决方案。
谢谢!
答案 0 :(得分:1)
最好为此目的使用a
标记。
<?php echo form_open('client/send_message'); ?>
<input type="text" name="message" required />
<button class="btn btn-primary btn-block">Send</button>
<a href="#" class="btn btn-default btn-block" data-toggle="modal" data-target="#my_modal">Send Email</a>
<?php echo form_close(); ?>
答案 1 :(得分:1)
希望这会对你有所帮助:
更改按钮表单提交更改的类型以提交
<?php echo form_open('client/send_message'); ?>
<input type="text" name="message" required />
<button type="submit" class="btn btn-primary btn-block">Send</button>
<button type="button" class="btn btn-default btn-block" data-toggle="modal" data-target="#my_modal">Send Email</button>
<?php echo form_close(); ?>
答案 2 :(得分:0)
<input type="button"/>
这不会提交表格,因为我们已将其指定为仅作为按钮。
<input type="submit"/>
这将提交表单,因为我们已将其指定为提交表单的按钮。