我遇到了一个似乎无法解决的问题。
首先,我有一个由专业人士建立的网站,我们与那家公司不再有工作关系。我现在自己管理网站。我有能力,但我绝不是一名经验丰富的 Web 开发人员。
背景:我们有一个使用多页表单呈现给最终用户的应用程序。该表单分 7 个步骤显示,但全部都是从一个 php 文件完成的,使用(我认为)jquery/javascript 循环执行这些步骤,并验证一些字段。在最后一步中,会显示一个摘要供用户提交。这很好用。
以下是我认为是处理页面循环的相关 javascript:
<script>
$(function () {
window.confirmLeave = true;
$('.datefield').datepicker();
var cache = {}; // caching inputs for the visited steps
$("#appForm").bind("step_shown", function(event,data){
if(data.isLastStep){ // if this is the last step...then
$("#summaryContainer").empty(); // empty the container holding the
$.each(data.activatedSteps, function(i, id){ // for each of the activated steps...do
if(id === "summary") return; // if it is the summary page then just return
cache[id] = $("#" + id).find(".input"); // else, find the div:s with class="input" and cache them with a key equal to the current step id
cache[id].detach().appendTo('#summaryContainer').show().find(":input").removeAttr("disabled"); // detach the cached inputs and append them to the summary container, also show and enable them
});
}else if(data.previousStep === "summary"){ // if we are movin back from the summary page
$.each(cache, function(id, inputs){ // for each of the keys in the cache...do
var i = inputs.detach().appendTo("#" + id).find(":input"); // put the input divs back into their normal step
if(id === data.currentStep){ // (we are moving back from the summary page so...) if enable inputs on the current step
i.removeAttr("disabled");
}else{ // disable the inputs on the rest of the steps
i.attr("disabled","disabled");
}
});
cache = {}; // empty the cache again
}
});
</script>
我还包含了以下表单的 html:
<form name="appForm" id="appForm" action="submit-app-exec.php" method="post"
enctype="multipart/form-data" autocomplete="off" onSubmit="showProgressBar()">
<fieldset class="step" id="page_1">
<div class="input">
<?php include("add-company/step1.html"); ?>
</div>
</fieldset>
<fieldset class="step" id="page_2">
<div class="input">
<?php include("add-company/step2.html"); ?>
</div>
</fieldset>
<fieldset class="step" id="page_3">
<div class="input">
<?php include("add-company/step3.html"); ?>
</div>
</fieldset>
<fieldset class="step" id="page_4">
<div class="input">
<?php include("add-company/step4.html"); ?>
</div>
</fieldset>
<fieldset class="step" id="page_5">
<div class="input">
<?php include("add-company/step5.html"); ?>
</div>
</fieldset>
<fieldset class="step" id="page_6">
<div class="input">
<?php include("add-company/step6.html"); ?>
</div>
</fieldset>
<fieldset class="step" id="page_7">
<div class="input">
<?php include("add-company/step7.html"); ?>
</div>
</fieldset>
<fieldset class="step" id="summary" >
<span class="font_normal_07em_black">Summary page</span><br />
<p>Please verify your information below.</p>
<div id="summaryContainer"></div>
</fieldset>
<div id="wizardNavigation">
<button class="navigation_button" onclick="javascript:saveApp()">Save</button>
<input class="navigation_button" id="back" value="Back" type="reset" />
<input class="navigation_button" id="next" value="Next" type="submit" onclick="javascript:noSaveApp()" />
<div class="clearFix"></div>
</div>
加载页面时,每个字段集都有额外的类和样式属性:
class="step ui-formwizard-content ui-helper-reset ui-corner-all" style="display: none;"
过程中用firebug观察,看到display: none;与该字段集交互时循环并更改为“阻止”。
问题:我们没有以任何方式让用户保存进度并稍后完成。我现在正在尝试这样做。我已经成功创建了“保存”按钮,它触发了一个 javascript 来更改表单的操作,它将数据发布到一个新的 php 文件,该文件处理和处理 POST 数据到 MySQL 中。这是可行的,但是,POST 仅传递当前查看的字段集中的数据,而不是 POST 所有数据。而且我无法弄清楚如何确保所有表单数据都已发布。任何指导或建议都会有所帮助。谢谢。
编辑:
我能够通过以下方式加载正确的页面:
$(function(){ $('#appForm').formwizard('show','" . $row["current_step"] . "'); });
这会加载正确的页面。现在的问题是,最后一步是一个摘要页面,显示最终提交的所有输入元素。但是,它似乎只显示已查看页面中的元素,我很确定是数组“data.activatedSteps”决定了元素是否在最终摘要中显示。你的代码会比我的更好地解决这个问题吗?再次感谢您对此的帮助。 –
最佳答案
<input>具有属性 'disable' 的对象不要在 post/get 中返回。
这是在您的问题中需要特别注意的 javascript。
if(id === data.currentStep){ // (we are moving back from the summary page so...) if enable inputs on the current step
i.removeAttr("disabled");
}else{ // disable the inputs on the rest of the steps
i.attr("disabled","disabled");
}
这就是以前的编码员控制用户可以编辑的内容的方式。如果您希望在用户首先点击您的保存按钮时发送回所有值
removeAttr("disabled");
从页面上的所有内容然后提交帖子/获取。
看起来以前的编码人员通过遍历页面上的所有数据并在此处不禁用它来完成此操作。
if(data.isLastStep){ // if this is the last step...then
$("#summaryContainer").empty(); // empty the container holding the
$.each(data.activatedSteps, function(i, id){ // for each of the activated steps...do
if(id === "summary") return; // if it is the summary page then just return
cache[id] = $("#" + id).find(".input"); // else, find the div:s with class="input" and cache them with a key equal to the current step id
cache[id].detach().appendTo('#summaryContainer').show().find(":input").removeAttr("disabled"); // detach the cached inputs and append them to the summary container, also show and enable them
});
}
因此,您可以在发布返回时调用该代码,也可以执行类似的操作以启用页面上的输入。
根据您的评论,我建议使用它来解决您的问题,以便您始终使用相同的实用程序和库来操作页面上的对象。而且 JQuery 非常方便。
$(':input.ui-wizard-content').each(function() {$( this ).removeAttr("disabled");});
:input获取页面上的所有输入。 .ui-wizard-content告诉 JQuery 只查找具有该类的输入,然后是 .each遍历每个对找到的对象运行 lambda 函数 ( function() {$( this ).removeAttr("disabled");} ) 的对象。
很难说是什么$row[]在你的代码中。它显然是一个容器,但你提供的代码有点断章取义,所以我不能确定它是什么。
也就是说,如果我只有 DOM(页面上的内容的 Java 脚本表示)可以使用并且我知道您之前发布的功能,我会做这样的事情。
替换
if(data.isLastStep){ // if this is the last step...then
$("#summaryContainer").empty(); // empty the container holding the
$.each(data.activatedSteps, function(i, id){ // for each of the activated steps...do
if(id === "summary") return; // if it is the summary page then just return
cache[id] = $("#" + id).find(".input"); // else, find the div:s with class="input" and cache them with a key equal to the current step id
cache[id].detach().appendTo('#summaryContainer').show().find(":input").removeAttr("disabled"); // detach the cached inputs and append them to the summary container, also show and enable them
});
}
与
if(data.isLastStep){
$("#summaryContainer").empty();
$('.input :input').detach().appendTo('#summaryContainer').show().find(":input").removeAttr("disabled");
}
这主要是从以前的编码员所做的事情中借来的。他假设表格中的所有内容都在 data.activatedSteps 中。因为他创建的工作流程,但情况已不再如此。所以你要么需要看看他在哪里添加数据到data.activatedSteps并在重新加载时以相同的方式将保存的内容放在那里。或者只使用忽略所有 data 的我的行东西,然后捕获每一个 <input>在类 input 的对象中并将其添加到容器中。
注意:JQuery 的 $(TEXT)使用与 CSS 相同的对象定义语法,并带有一些特别易于使用的插件,如“:input”。对我所说的内容有很好的引用here CSS 引用和 JQuery 特殊选择器语法检查 here .这就是我知道如何用非常紧凑的语句编写能够捕获您感兴趣的所有内容的方式。
关于javascript - 多页表单提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19365858/
文章目录git常用命令(简介,详细参数往下看)Git提交代码步骤gitpullgitstatusgitaddgitcommitgitpushgit代码冲突合并问题方法一:放弃本地代码方法二:合并代码常用命令以及详细参数gitadd将文件添加到仓库:gitdiff比较文件异同gitlog查看历史记录gitreset代码回滚版本库相关操作远程仓库相关操作分支相关操作创建分支查看分支:gitbranch合并分支:gitmerge删除分支:gitbranch-ddev查看分支合并图:gitlog–graph–pretty=oneline–abbrev-commit撤消某次提交git用户名密码相关配置g
我遇到了一个非常奇怪的问题,我很难解决。在我看来,我有一个与data-remote="true"和data-method="delete"的链接。当我单击该链接时,我可以看到对我的Rails服务器的DELETE请求。返回的JS代码会更改此链接的属性,其中包括href和data-method。再次单击此链接后,我的服务器收到了对新href的请求,但使用的是旧的data-method,即使我已将其从DELETE到POST(它仍然发送一个DELETE请求)。但是,如果我刷新页面,HTML与"new"HTML相同(随返回的JS发生变化),但它实际上发送了正确的请求类型。这就是这个问题令我困惑的
我在ruby表单中有一个提交按钮f.submitbtn_text,class:"btnbtn-onemgt12mgb12",id:"btn_id"我想在不使用任何javascript的情况下通过ruby禁用此按钮 最佳答案 添加disabled:true选项。f.submitbtn_text,class:"btnbtn-onemgt12mgb12",id:"btn_id",disabled:true 关于ruby-on-rails-如何在Rails中添加禁用的提交按钮,我们在St
保存成功后可以回滚吗?让我有一个带有属性名称、电子邮件等的用户模型。例如u=User.newu.name="test_name"u.email="test@email.com"u.save现在记录将成功保存在数据库中,之后我想回滚我的事务(不是销毁或删除)。有什么想法吗? 最佳答案 您可以通过交易来做到这一点,请参阅http://markdaggett.com/blog/2011/12/01/transactions-in-rails/例子:User.transactiondoUser.create(:username=>'Nemu
我有这个:AccountSummary我想单击该链接,但在使用link_to时出现错误。我试过:bot.click(page.link_with(:href=>/menu_home/))bot.click(page.link_with(:class=>'top_level_active'))bot.click(page.link_with(:href=>/AccountSummary/))我得到的错误是:NoMethodError:nil:NilClass的未定义方法“[]” 最佳答案 那是一个javascript链接。Mechan
我看到有关未找到文件min.map的错误消息:GETjQuery'sjquery-1.10.2.min.mapistriggeringa404(NotFound)截图这是从哪里来的? 最佳答案 如果ChromeDevTools报告.map文件的404(可能是jquery-1.10.2.min.map、jquery.min.map或jquery-2.0.3.min.map,但任何事情都可能发生)首先要知道的是,这仅在使用DevTools时才会请求。您的用户不会遇到此404。现在您可以修复此问题或禁用sourcemap功能。修复:获取文
我有一个用Rails3编写的站点。我的帖子模型有一个名为“内容”的文本列。在帖子面板中,html表单使用tinymce将“content”列设置为textarea字段。在首页,因为使用了tinymce,post.html.erb的代码需要用这样的原始方法来实现。.好的,现在如果我关闭浏览器javascript,这个文本区域可以在没有tinymce的情况下输入,也许用户会输入任何xss,比如alert('xss');.我的前台会显示那个警告框。我尝试sanitize(@post.content)在posts_controller中,但sanitize方法将相互过滤tinymce样式。例如
我正在尝试使用Rugged以编程方式创建对现有存储库的提交(libgit2的Ruby绑定(bind))。我已尝试遵循RuggedREADME中提供的文档,但我认为它与代码库的当前状态不太匹配。当我尝试运行以下代码时,我不断收到错误消息:require'rugged'#Createaninstanceoftheexistingrepositoryrepo=Rugged::Repository.new('/full/path/to/repo')#grabthecurrentTimeobjectfornowcurr_time=Time.now#writeanewblobtothereposi
出于某种原因,我必须为Firefox禁用javascript(手动,我们按照提到的步骤执行http://support.mozilla.org/en-US/kb/javascript-settings-for-interactive-web-pages#w_enabling-and-disabling-javascript)。使用Ruby的SeleniumWebDriver如何实现这一点? 最佳答案 是的,这是可能的。而是另一种方式。您首先需要查看链接Selenium::WebDriver::Firefox::Profile#[]=
我是Ruby和Watir-Webdriver的新手。我有一套用VBScript编写的站点自动化程序,我想将其转换为Ruby/Watir,因为我现在必须支持Firefox。我发现我真的很喜欢Ruby,而且我正在研究Watir,但我已经花了一周时间试图让Webdriver显示我的登录屏幕。该站点以带有“我同意”区域的“警告屏幕”开头。用户点击我同意并显示登录屏幕。我需要单击该区域以显示登录屏幕(这是同一页面,实际上是一个表单,只是隐藏了)。我整天都在用VBScript这样做:objExplorer.Document.GetElementsByTagName("area")(0).click