您好,我正在使用步骤形式步骤1,步骤2等
在这里,我应用jQuery并转到下一页,但我的问题是我没有在下一步的请求中获取第一步的数据。 这只是 Sinlge 页面上的步骤,它们只显示隐藏和阻止。我应该怎么做才能进入 PHP 请求所有步骤数据,直到最后一步完成
<form>
<div class="step1">
<input type="text" name="firstname">
</div>
<div class="step2">
<input type="text" name="lastname">
<div>
<input type="submit" name="sub">
<input type="button" name="next">
<input type="button" name"previous">
</form>
在这里,当
这取决于
你的PHP实现,但你有两个选择:
1-在每一步之后使用AJAX将数据发送回服务器。2-每个步骤使用单独的页面。
单击步骤 1 中的按钮时,
- 插入
到相应的表中并获取插入的id
将插入的 id 值保存在窗体中的某个隐藏类型中。
单击步骤 2 中的按钮时,
- 您需要使用您在表单中保存的 ID 更新插入的表格行数据中的相应列及其值
继续相同的过程,直到完成所有步骤。
<script>
$(document).ready(function() {
$("#next").click(function() {
var currentStep = $('#currentStep').val(); // based on the step you need use some switch or conditional block to pass data and store it accordingly.
// insertedId ==0 means you need to insert into table, if it not you need update the column in table
var formdata = {insertedId:$("#insertedId").val(),currentStep:currentStep, first:$("#first").val()};
$.ajax({
type: "POST",
url: "form.php",
dataType:'json',
data: formdata
})
.done(function( data ) {
var NextStep =parseInt(currentStep)+1;
$("#currentStep").val(NextStep);
$("#insertedId").val(data.insertedId);
$("#step"+currentStep).hide();
$("#step"+NextStep).show();
});
});
});
</script>
.HTML:
<div id="step1">Step 1:
<input type="text" name="first" id="first" value="">
</div>
<div id="step2" style="display:none;">Step 2:
<input type="text" name="last" id="last" value="">
</div>
<input type="hidden" name="insertedId" id="insertedId">
<input type="hidden" name="currentStep" id="currentStep" value="1">
<button id="next">Next</button>