模态中的输入按钮未提交外部表单

时间:2017-09-13 19:50:09

标签: html twitter-bootstrap-3 django-templates bootstrap-modal

我用Django创建了一个内联formset。填写完表单并且用户单击Submit后,我在Bootstrap模式中编码,弹出提醒。模态的页脚包含HTML输入,因此可以从模态提交外部表单。

我遇到的问题是提交按钮不提交表单,因此可以将其保存到数据库并通过电子邮件发送。有没有办法使用模态完成此操作?

模板:

{% extends "reports/base.html" %}
{% load static %}
{% block body_block %}
<font color="green">
          <h4 >Company</h4>
</font>
<h3>Please enter your nightly reports in the form below.</h3>
<br>
<p>If you would like to add a new line to a category, select <font color="blue">add New Line Item</font> under each category.
When finished, click on <strong><font color="gray">Save and Email to Corporate</font></strong> button at the bottom of the form.</h4>
Once the form is sent, the form will refresh with the information you have entered. If you notice an error after you sent the form, edit the error and click the <strong><font color="gray">Save and Email to Corporate</font></strong> button again to update and resend.</p>
<br>
<h5>If you would like a blank form, click <a href="{% url 'reports:storenightlyreports' %}"><font color="green"> here</font>.</a></h5>
<br>
<br>

<div class="container-fluid">
    <form class="form-inline" action="" method="post">
        {% csrf_token %}
        {{ form }}

        <table class="table">
            {{ formset_new.management_form }}
            <div>
            <br><h4><strong>New</strong></h4><br>
            {% include "reports/formsets.html" with formset=formset_new formset_class_name='new' prefix="new" %}
            </div>
        </table>
        <table class="table">
            {{ formset_renewal.management_form }}
            <div>
                <br><h4><strong>Renewals</strong></h4><br>
            {% include "reports/formsets.html" with formset=formset_renewal formset_class_name='renewal' prefix="renewal" %}
            </div>
        </table>
       </div>
    </form>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="{% static 'js/jquery.formset.js' %}"></script>
<br>

<div class="container">
  <!-- Trigger the modal with a button -->
  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal"><strong>Submit</strong></button>

  <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Before You Submit!!</h4>
        </div>
        <div class="modal-body">
            <p>Please review and make sure that all line items are correct and that the <strong>"Check if No New Items"</strong> is checked if there are no new items for that catagory. If all is correct, please select the <strong>Save and Email</strong> button.</p>
        </div>
        <div class="modal-footer">
            <input type="submit" class="btn btn-primary" value="Save and Email to Corporate">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>

    </div>
  </div>

</div>

{% endblock %}

1 个答案:

答案 0 :(得分:0)

在研究HTML输入元素后,我发现您可以使用private void lbFavo_MouseDoubleClick(object sender, MouseEventArgs e) { if (lbFavo.SelectedItem != "www.nu.nl" || lbFavo.SelectedItem != "www.weeronline.nl" || lbFavo.SelectedItem != "www.buienradar.nl") { webBrowser.Navigate(lbFavo.SelectedItem.ToString()); tabWeb.TabPages[0].Text = lbFavo.SelectedItem.ToString(); } if (cbGeschiedenis.Items.IndexOf(lbFavo.SelectedItem.ToString()) == cbGeschiedenis.SelectedIndex) { webBrowser.Navigate(lbFavo.SelectedItem.ToString()); cbGeschiedenis.Items.Add(lbFavo.SelectedItem.ToString()); } else { ErrorMelding.SetError(txtURL, "U moet zich bezig houden met werk en niet met prive!!"); } } } 属性来标识id元素,并使用<form>中的form属性来调用ID在Bootstrap Modal中编码的元素。相关的更新代码如下。

<input>

希望这可以帮助那些使用SO作为研究工具的人。