我不确定如何准确表达这个问题,但我会尽力而为。 我有一个表格可以从用户那里收集有关工作经历的数据。目前我的表单如下所示:
<form name="EmploymentHistory" action="Form E.php" method="post">
<h2>Employment History</h2>
<label>Last/Current employer</label>
<input type='text' name='LastCurrentemployer'>
<hr> <label>Position</label>
<input type='text' name='Position'>
<hr> <label>Date Started</label>
<input type='text' name='DateStarted'>
<hr> <label>Date Finished</label>
<input type='text' name ='DateFinished'>
<hr> <label>Supervised by</label>
<input type='text' name = 'Supervisedby'>
<hr> <label>Contact Details for Boss</label>
<input type='text' name='ContactDetailsForBoss'>
<hr> <button type='button'>Add another job</button> <br>
<hr> <input type="submit" value="Next">
</form>
我的问题是“添加另一份工作”按钮没有任何作用。
我怎样才能让用户在他们的就业历史中输入多个工作,以便每个工作都作为新记录输入到我的数据库中,而提交按钮(下一步)只需要点击一次?
我正在考虑尝试设置一个数组,然后使用 arraypush 添加每个条目,例如:
$pastemployers = array ();
arraypush $pastemployers(POST_['LastCurrentemployer']);
然后循环将每一个添加为一个新记录,例如:
for ($x = 0; $x < count(pastemployers); $x++){
echo "<input name='pastemployers" . $x . "' value='" . $pastemployers[$x] . "'> </input>";
我确信有更好的方法来执行此操作,但我无法在网上找到答案或解决问题。我的大部分搜索都返回有关复选框或多个提交按钮的结果(对我没有帮助)。请帮忙
最佳答案
首先,如下所示更改您的表单,并使用 addAnotherJob() 创建第一个跨度的克隆(使用 jQuery)并更改每个表单字段的 ID。提交此表单后,您将获得雇主详细信息的数组。
<form name="EmploymentHistory" action="Form.php" method="post">
<h2>Employment History</h2>
<span class="span_clone">
<label>Last/Current employer</label>
<input type='text' id='LastCurrentemployer_0' name='LastCurrentemployer[]'>
<hr> <label>Position</label>
<input type='text' id='Position_0' name='Position[]'>
<hr> <label>Date Started</label>
<input type='text' id="DateStarted_0" name='DateStarted[]'>
<hr> <label>Date Finished</label>
<input type='text' id='DateFinished_0' name ='DateFinished[]'>
<hr> <label>Supervised by</label>
<input type='text' id='Supervisedby_0' name = 'Supervisedby[]'>
<hr> <label>Contact Details for Boss</label>
<input type='text' id='ContactDetailsForBoss_0' name='ContactDetailsForBoss[]'>
<hr> <button id='add-another-job-0' type='button' onclick= 'addAnotherJob()'>Add another job</button> <br>
</span>
<hr> <input type="submit" value="Next">
</form>
关于html 表单输入 - 每个输入字段的多个答案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30977288/
Rails2.3可以选择随时使用RouteSet#add_configuration_file添加更多路由。是否可以在Rails3项目中做同样的事情? 最佳答案 在config/application.rb中:config.paths.config.routes在Rails3.2(也可能是Rails3.1)中,使用:config.paths["config/routes"] 关于ruby-on-rails-Rails3中的多个路由文件,我们在StackOverflow上找到一个类似的问题
我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h
我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib
我有多个ActiveRecord子类Item的实例数组,我需要根据最早的事件循环打印。在这种情况下,我需要打印付款和维护日期,如下所示:ItemAmaintenancerequiredin5daysItemBpaymentrequiredin6daysItemApaymentrequiredin7daysItemBmaintenancerequiredin8days我目前有两个查询,用于查找maintenance和payment项目(非排他性查询),并输出如下内容:paymentrequiredin...maintenancerequiredin...有什么方法可以改善上述(丑陋的)代
我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何
我有一个表单,其中有很多字段取自数组(而不是模型或对象)。我如何验证这些字段的存在?solve_problem_pathdo|f|%>... 最佳答案 创建一个简单的类来包装请求参数并使用ActiveModel::Validations。#definedsomewhere,atthesimplest:require'ostruct'classSolvetrue#youcouldevencheckthesolutionwithavalidatorvalidatedoerrors.add(:base,"WRONG!!!")unlesss
我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢
在我的Controller中,我通过以下方式在我的index方法中支持HTML和JSON:respond_todo|format|format.htmlformat.json{renderjson:@user}end在浏览器中拉起它时,它会自然地以HTML呈现。但是,当我对/user资源进行内容类型为application/json的curl调用时(因为它是索引方法),我仍然将HTML作为响应。如何获取JSON作为响应?我还需要说明什么? 最佳答案 您应该将.json附加到请求的url,提供的格式在routes.rb的路径中定义。这
我有一个具有一些属性的模型:attr1、attr2和attr3。我需要在不执行回调和验证的情况下更新此属性。我找到了update_column方法,但我想同时更新三个属性。我需要这样的东西:update_columns({attr1:val1,attr2:val2,attr3:val3})代替update_column(attr1,val1)update_column(attr2,val2)update_column(attr3,val3) 最佳答案 您可以使用update_columns(attr1:val1,attr2:val2
所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择