使用多步骤表单POST的问题

时间:2014-11-23 19:19:32

标签: javascript jquery html forms post

我有一个3阶段表单,用户输入数据,我想使用POST命令,因此数据可用于另一页面。使用单一表单时,POST工作正常,如下所示

<form action="otherpage.php" method="post">
Question:  <input type="text" name="something" /><br />
<input type="submit" name="submit" value="Submit me!" />
</form>

但是现在,我有一个3阶段表单,用户在每个阶段输入一些数据。屏幕转换使用jquery,除了使用POST之外,每个人看起来都很好。

<form id="msform" action="otherpage.php" method="post">
    <!-- progressbar -->
    <ul id="progressbar">
        <li class="active">Screen1</li>
        <li>Screen2</li>
        <li>Screen3</li>
    </ul>
    <!-- fieldsets -->
    <fieldset>
        <h2 class="fs-title">Title</h2>
        <h3 class="fs-subtitle">Question?</h3>
        <input type="text" name="variable1" placeholder="blah" />
        <input type="button" name="next" class="next action-button" value="Next" />
    </fieldset>
    <fieldset>
        <h2 class="fs-title">Student Status</h2>
        <h3 class="fs-subtitle">Are you are student?</h3>
        <input type="radio" name="student" value="yes" checked>Yes
        <input type="radio" name="student" value="no">No
        <input type="button" name="previous" class="previous action-button" value="Previous" />
        <input type="button" name="next" class="next action-button" value="Next" />
    </fieldset>
    <fieldset>
        <h2 class="fs-title">Dropdown</h2>
        <h3 class="fs-subtitle">Dropdown Question?</h3>
        <select name="mydropdown">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        </select>
        <input type="button" name="previous" class="previous action-button" value="Previous" />
        <input type="submit" name="submit" class="submit action-button" value="Submit" />
    </fieldset>

</form>

现在当我点击提交按钮时,我不再被带到&#34; otherpage.php&#34;

我尝试在表单标签和发布周围包装提交按钮,但这也不起作用。我是一个新手,所以任何帮助将不胜感激。

谢谢!

编辑: -

如果有帮助,这是javascript代码:

var current_fs, next_fs, previous_fs; //fieldsets
var left, opacity, scale; //fieldset properties which we will animate
var animating; //flag to prevent quick multi-click glitches

$(".next").click(function(){
    if(animating) return false;
    animating = true;

    current_fs = $(this).parent();
    next_fs = $(this).parent().next();

    //activate next step on progressbar using the index of next_fs
    $("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");

    //show the next fieldset
    next_fs.show(); 
    //hide the current fieldset with style
    current_fs.animate({opacity: 0}, {
        step: function(now, mx) {
            //as the opacity of current_fs reduces to 0 - stored in "now"
            //1. scale current_fs down to 80%
            scale = 1 - (1 - now) * 0.2;
            //2. bring next_fs from the right(50%)
            left = (now * 50)+"%";
            //3. increase opacity of next_fs to 1 as it moves in
            opacity = 1 - now;
            current_fs.css({'transform': 'scale('+scale+')'});
            next_fs.css({'left': left, 'opacity': opacity});
        }, 
        duration: 800, 
        complete: function(){
            current_fs.hide();
            animating = false;
        }, 
        //this comes from the custom easing plugin
        easing: 'easeInOutBack'
    });
});

$(".previous").click(function(){
    if(animating) return false;
    animating = true;

    current_fs = $(this).parent();
    previous_fs = $(this).parent().prev();

    //de-activate current step on progressbar
    $("#progressbar li").eq($("fieldset").index(current_fs)).removeClass("active");

    //show the previous fieldset
    previous_fs.show(); 
    //hide the current fieldset with style
    current_fs.animate({opacity: 0}, {
        step: function(now, mx) {
            //as the opacity of current_fs reduces to 0 - stored in "now"
            //1. scale previous_fs from 80% to 100%
            scale = 0.8 + (1 - now) * 0.2;
            //2. take current_fs to the right(50%) - from 0%
            left = ((1-now) * 50)+"%";
            //3. increase opacity of previous_fs to 1 as it moves in
            opacity = 1 - now;
            current_fs.css({'left': left});
            previous_fs.css({'transform': 'scale('+scale+')', 'opacity': opacity});
        }, 
        duration: 800, 
        complete: function(){
            current_fs.hide();
            animating = false;
        }, 
        //this comes from the custom easing plugin
        easing: 'easeInOutBack'
    });
});

$(".submit").click(function(){
    return true;
})

编辑2:

也许吧,因为我现在正在使用javascript,而不是之前,这意味着我不能像以前一样使用POST吗?我一直在寻找其他人的问题和互联网,但真的无法找到解决这个问题的下一步。

1 个答案:

答案 0 :(得分:1)

好的,我实际上解决了它,我需要删除代码:

class="submit action-button"

从我的提交按钮,因为这阻止我使用'POST'命令,而是调用jquery文件,其中只有一个返回:true。

我想我只是个白痴!