【问题标题】:Problems using POST with a Multi Step Form使用带有多步骤表单的 POST 时出现问题
【发布时间】:2014-11-23 19:19:31
【问题描述】:

我有一个 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>

现在当我点击提交按钮时,我不再被带到“otherpage.php”

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

谢谢!

编辑:-

如果有帮助,这是 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 吗?我一直在搜索其他人的问题和互联网,但真的找不到解决这个问题的下一步。

【问题讨论】:

    标签: javascript jquery html forms post


    【解决方案1】:

    好的我确实解决了,我需要删除代码:

    class="submit action-button"
    

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

    我想我只是个白痴!

    【讨论】:

    • 另外,如果其他人遇到这种情况,请确保在 JADE 中将 FORM 设置为 FORM 元素而不是 DIV。 form#msform(action='/home', method='get')
    猜你喜欢
    • 1970-01-01
    • 2015-04-17
    • 2013-05-19
    • 1970-01-01
    • 2018-01-19
    • 2021-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多