简体   繁体   English

在twitter bootstrap向导中提交个人表单

[英]submit individual form in twitter bootstrap wizard

I am using twitter bootstrap from wizard, and i want to submit 4 form in wizard, http://vadimg.com/twitter-bootstrap-wizard-example/examples/basic-formvalidation.html# 我正在使用来自向导的twitter bootstrap,我想在向导中提交4个表单, http://vadimg.com/twitter-bootstrap-wizard-example/examples/basic-formvalidation.html#

Below is my code on each next button press, 下面是每次按下按钮时我的代码,

       onNext: function (tab, navigation, index) {
        if(index == 1) {
            if(form_header.valid() === true) {

                    $('#report_header_fm').submit(function(){
                    console.log('test123');
                    $.ajax({
                        type: "POST",
                        url: baseURL + "index.php/addNewReport",
                        data: $("#report_header_fm").serialize(),
                        success: function(data)
                        {
                            console.log('test');
                        }

                        });  //Ajax end
                });

                }
            else
            {
                 return false;
            }
            }
            handleTitle(tab, navigation, index);

            },

I have form with 5 inputs and id=report_header_fm, 我有5个输入的表单,id = report_header_fm,

Now when i click on next, i can see form validation occurs but form does not get submitted, Note- I am not clicking on submit button but there is next button-- 现在,当我单击“下一步”时,我可以看到发生了表单验证,但是表单没有提交,请注意-我没有单击“提交”按钮,但是有一个下一个按钮-

<input type="submit" class="btn green-haze" value="Save">

So what i want is to submit a form when clicked on next, here validation occurs when click on next but submit is not happening, I could not see 'test123' in console, 所以我想要的是单击“下一步”时提交一个表单,单击“下一步”但未进行提交时会在此处进行验证,我在控制台中看不到“ test123”,

In short, how do i submit form without hitting submit button? 简而言之,如何在不点击提交按钮的情况下提交表格?

Thanks, 谢谢,

Here is a list of things you can change here to make it work, hopefully. 这是您可以在此处进行更改以使其能够正常工作的列表。 Try it out. 试试看。

onNext: function (tab, navigation, index) {
        var wizard = this;
        if(index == 1) {
            if(form_header.valid() === true) {
                    //below line are not needed, so comment it out 
                    //$('#report_header_fm').submit(function(){
                    console.log('test123');
                    $.ajax({
                        type: "POST",
                        url: baseURL + "index.php/addNewReport",
                        data: $("#report_header_fm").serialize(),
                        success: function(data)
                        {
                            console.log('test');
                            //At this point you will need to call the show method with index of tab you want to move to.
                            wizard.show(2);
                        }

                        });  //Ajax end
                //});
                  // this would run before the ajax completes
                  return false;
            } else {
                 return false;
            }
 }
onNext: function (tab, navigation, index) {
    if(index == 1) {
        if(form_header.valid() === true) {
                $.ajax({
                    type: "POST",
                    url: baseURL + "index.php/addNewReport",
                    data: $("#report_header_fm").serialize(),
                    success: function(data)
                    {
                        console.log('test');
                        this.show(2);
                    }

                    });
        } else {
             return false;
        }
 }
onNext: function (tab, navigation, index) {
                if(index == 1) {
            if(form_header.valid() === true) {

                    console.log('test123');
                    $.ajax({
                        type: "POST",
                        url: baseURL + "index.php/addNewReport",
                        data: $("#report_header_fm").serialize(),
                        success: function(data)
                        {
                            console.log('test');
                           //index of tab 
                           // this will move to next tab only after getting successful response    
                           $('#rootwizard').bootstrapWizard('show',1);
                        }

                        });  //Ajax end

                 //required so that control does not move to next tab unless response is fetched
                  return false;
            } else {
                 return false;
            }
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM