一页,两个模态(2种不同的动作)

时间:2017-10-14 17:52:36

标签: jquery twitter-bootstrap-3

我有一个带有2个按钮的页面,它们调用2个模态。

每个模态都有一个SUBMIT按钮,我想执行不同的动作。

我的问题是,当我打开第二个模态并尝试提交表单时,第一个模态显示必填字段的警告。

如何单独执行操作?在这种情况下,或发送添加联系表格或发送添加文件表格?

谢谢大家。

按钮1添加联系人:

<a data-toggle="modal" href="#add_contact"><i class="icon-user-plus"></i> <? echo $msg['new']; ?> <? echo $msg['contact']; ?></a>

按钮2添加文档

<a data-toggle="modal" href="#add_document"><i class="icon-user-plus"></i> <? echo $msg['new']; ?> <? echo $msg['document']; ?></a>

1ST模式添加联系人

<!-- Add Contact MODAL -->
        <div id="add_contact" class="modal fade">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h5 class="modal-title"><? echo $msg['add_contact']; ?></h5>
                    </div>
                    <form method="post" id="message_add" class="form-validate-jquery" action="suppliers_inc.sql.php">

                        <input type="hidden" name="a" value="add_contact" />
                        <input type="hidden" name="supplier_id" value="<? echo $supplier_id ?>" />

                        <div class="modal-body">
                            <div class="form-group">
                                <div class="row">
                                    <div class="col-sm-6">
                                        <label><? echo $msg['contact_type']; ?> <span class="text-danger">*</span></label>
                                        <select name="contact_type_id" class="select-search" required="required" data-placeholder="">
                                        <?php
                                            $query_contact_type = "SELECT DISTINCT type_id, type_description FROM supplier_contacts_type ORDER BY type_description";
                                            $result_contact_type = $mysqli->query($query_contact_type);
                                            while ($row_contact_type = $result_contact_type->fetch_assoc()) {
                                                echo "<option></option>";
                                                echo "<option value=\"{$row_contact_type['type_id']}\">";
                                                echo $row_contact_type['type_description'];
                                                echo "</option>";
                                            }
                                        ?>
                                        </select>
                                    </div>

                                    <div class="col-sm-6">
                                        <label><? echo $msg['position']; ?> <span class="text-danger">*</span></label>
                                        <input type="text" name="contact_position" required="required" class="form-control">
                                    </div>

                                </div>
                            </div>

                            <div class="form-group">
                                <div class="row">
                                    <div class="col-sm-6">
                                        <label><? echo $msg['name']; ?> <span class="text-danger">*</span></label>
                                        <input type="text" name="contact_name" required="required" class="form-control">
                                    </div>

                                    <div class="col-sm-6">
                                        <label><? echo $msg['surname']; ?> <span class="text-danger">*</span></label>
                                        <input type="text" name="contact_surname" required="required" class="form-control">
                                    </div>
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="row">
                                    <div class="col-sm-4">
                                        <label><? echo $msg['telephone']; ?> <span class="text-danger">*</span></label>
                                        <input type="text" name="contact_telephone" placeholder="Telefone FIXO" data-mask="99 9999-9999" required="required" class="form-control">
                                    </div>

                                    <div class="col-sm-4">
                                        <label><? echo $msg['int']; ?></label>
                                        <input type="text" name="contact_int" class="form-control">
                                    </div>

                                    <div class="col-sm-4">
                                        <label><? echo $msg['hours']; ?></label>
                                        <input type="text" name="contact_hours" class="form-control">
                                    </div>
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="row">
                                    <div class="col-sm-3">
                                        <label><? echo $msg['mobile']; ?></label>
                                        <input type="text" name="contact_mobile" placeholder="Celular" data-mask="99 9-9999-9999" class="form-control">
                                    </div>

                                    <div class="col-sm-6">
                                        <label><? echo $msg['email']; ?></label>
                                        <input type="text" name="contact_email" class="form-control">
                                    </div>

                                    <div class="col-sm-3">
                                        <label><? echo $msg['date_of_birth']; ?></label>
                                        <input type="text" name="contact_date_of_birth" placeholder="dd/mm/aaaa" data-mask="99/99/9999" class="form-control">
                                    </div>                                      
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="row">

                                    <div class="col-sm-4">
                                        <div class="checkbox">
                                            <label>
                                                <input type="checkbox" name="contact_default" class="control-primary">
                                                <? echo $msg['default_contact']; ?>
                                            </label>
                                        </div>
                                    </div>

                                </div>
                            </div>

                        </div>

                        <div class="modal-footer">
                            <button type="button" class="btn btn-link" data-dismiss="modal"><? echo $msg['close']; ?></button>
                            <button type="submit" class="btn btn-primary"><? echo $msg['save']; ?> <i class="icon-arrow-right14 position-right"></i></button>
                        </div>

                    </form>
                </div>
            </div>
        </div>
        <!-- /Add Contact MODAL -->

2ND模式添加文档

            <!-- Add Document MODAL -->
        <div id="add_document" class="modal fade">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h5 class="modal-title"><? echo $msg['add_document']; ?></h5>
                    </div>
                    <form method="post" id="document_add" class="form-validate-jquery" action="suppliers_inc.sql.php">

                        <input type="hidden" name="a" value="add_document" />
                        <input type="hidden" name="supplier_id" value="<? echo $supplier_id ?>" />

                        <div class="modal-body">
                            <div class="form-group">
                                <div class="row">
                                    <div class="col-sm-6">
                                        <label><? echo $msg['document_classification']; ?> <span class="text-danger">*</span></label>
                                        <select name="classification_id" class="select-search" required="required" data-placeholder="">
                                        <?php
                                            $query_document_classification = "SELECT DISTINCT classification_id, classification_description FROM supplier_documents_classification ORDER BY classification_description";
                                            $result_document_classification = $mysqli->query($query_document_classification);
                                            while ($row_document_classification = $result_document_classification->fetch_assoc()) {
                                                echo "<option></option>";
                                                echo "<option value=\"{$row_document_classification['classification_id']}\">";
                                                echo $row_document_classification['classification_description'];
                                                echo "</option>";
                                            }
                                        ?>
                                        </select>
                                    </div>

                                </div>
                            </div>

                            <div class="form-group">
                                <div class="row">
                                    <div class="col-sm-12">
                                        <label><? echo $msg['description']; ?> <span class="text-danger">*</span></label>
                                        <input type="text" name="document_description" required="required" class="form-control">
                                    </div>
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="row">
                                    <div class="col-sm-4">
                                        <label><? echo $msg['issue_date']; ?></label>
                                        <input type="text" name="contact_date_of_birth" placeholder="dd/mm/aaaa" data-mask="99/99/9999" class="form-control">
                                    </div>  

                                    <div class="col-sm-4">
                                        <label><? echo $msg['expiry_date']; ?></label>
                                        <input type="text" name="contact_date_of_birth" placeholder="dd/mm/aaaa" data-mask="99/99/9999" class="form-control">
                                    </div>  
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="row">

                                    <div class="col-sm-4">
                                        <div class="checkbox">
                                            <label>
                                                <input type="checkbox" name="contact_default" class="control-primary">
                                                <? echo $msg['expiry_notification']; ?>
                                            </label>
                                        </div>
                                    </div>
                                    <div class="col-sm-4">
                                        <div class="checkbox">
                                            <label>
                                                <input type="checkbox" name="contact_default" class="control-primary">
                                                <? echo $msg['lock_supplier']; ?>
                                            </label>
                                        </div>
                                    </div>

                                </div>
                            </div>

                        </div>

                        <div class="modal-footer">
                            <button type="button" class="btn btn-link" data-dismiss="modal"><? echo $msg['close']; ?></button>
                            <button type="submit" class="btn btn-primary"><? echo $msg['save']; ?> <i class="icon-arrow-right14 position-right"></i></button>
                        </div>

                    </form>
                </div>
            </div>
        </div>
        <!-- /Add Document MODAL -->

1 个答案:

答案 0 :(得分:0)

问题必须出在你的javascript / jquery表单提交处理函数

$('form#message_add').on('submit',function(){
   //do something
});

$('form#document_add').on('submit',function(){
   //do something
});