解析数组,其中包含输入名称和值回形式为只读 [英] Parse array that contains input names and values back into a form as readonly

查看:203
本文介绍了解析数组,其中包含输入名称和值回形式为只读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:我要我的ColdFusion表单数据保存到一个数组,该数组存储到数据库中的列。我将与此阵列正在调用数据库中的数据,并分析它放回我的形式,但作为做的唯一的事情只读。该数组将包含输入名称和值。

Background: I am going to save my ColdFusion forms data into an array and store that array into the column of a database. The only thing I will be doing with this array is making a call to the database for the data and parsing it back into my form but as "Read Only". The array will contain both the input name and value.

问:在我的ColdFusion查询已为阵列的数据,这将是该数据解析回我的表格的最佳工艺数据库之后?我一定要重新创建我的形式在一个循环?或者,我可以针对输入和并添加值,因为我知道他们的名字?

Question: In ColdFusion after I have queried the database for the array data what would be the best process to parse the data back into my form? Do I have to recreate my form in a loop? Or can I target the inputs and and add the values since I will know their names?

也就是在那里保存数据的序列化JSON数据诗句使用ColdFusion创建一个数组什么价值?

Also is there any value in saving the data as serialized JSON data verse an array created with ColdFusion?

**** ***编辑

****EDIT***

下面是我的数据的工作流程的概要。其中一些项目,其中客户端请求的。

Below is an outline of the workflow of my data. Some of these items where requested by the client.


  1. 用户完成表格65的输入。

  1. User completes form with 65 inputs.

在提交的所有形式的数据被存储在其中加入到数据库的阵列。该数据库还具有以下数据相加。独特的数字标识符,提交日期,提交表单(从Session变量拉)的用户ID,最后被添加到数据库中的未分配状态,

On Submit all of the form data is stored in an array which is added to a database. The database also has the following data added. A unique numerical identifier, Submission Date, User ID that submitted the form (pulled from a Session variable), and finally a status of "not assigned" is added to the database

这是管理员检查一个单独的页面上的队列。该队列简单的拉仍在所有表单提交的未分配的地位。该阵列是不是在这个队列中。

An admin checks a queue on a separate page. That queue simple pulls all form submissions that are still in "not assigned" status. The array is not used in this queue.

如果管理员选择在队列中的一个条目以下页面加载相同的形式,但我会用数组来填充值到表单中并设置所有字段为只读。管理员从字面上只需要从表单字段的值复制并粘贴到不同的系统。 (是的,我知道这听起​​来很乏味,但这个特定的客户有没有其他的选择,这实际上比他们目前正在使用的过程中更好的。)

If an admin selects one of the entries in the queue the following page loads the exact same form but I will use the array to populate the values into the form and set all fields to read only. The admin literally only needs to copy and paste the values from the form fields into a different system. (Yes I know it sounds tedious but for this specific client there is no other option and this is actually better than the process they are currently using.)

该阵列将数据从字面上永远不会被用于别的以外,以确保所有的数据收集。

The array data will literally never be used for anything else other than to make sure all of the data is collected.

该阵列中的数据将总是要加载作为一个整体,将永远不会被更改一次提交。

The array data will always have to be loaded as a whole and will never be changed once submitted.

我希望这有助于清理我为什么问这些问题。谢谢

I hope this helps clear up why I am asking these questions. THanks

推荐答案

您可以做这样的事情。比方说,我存储汽车的preferential方面。 1997年本田雅阁。你可以在它的数据存储是这样的。

First, what pankaj means.

You can do something like this. Let's say I'm storing preferential aspects of a car. 1997 Honda Accord. You might store data in about it like this.

汽车表

CarID (PrimKey) | Make  | Model     | Year
--------------------------------------------
47              | Honda | Accord    | 1997
48              | Chevy | Malibu    | 2005

然后,我可以有一个名为CarSpecs一个单独的表

And then I can have a separate table called CarSpecs

SpecID (PrimKey) | CarID | SpecName | SpecValue
-----------------------------------------------
1001             | 47    | Color    | Red
1002             | 47    | Transmsn | Auto
1003             | 47    | Doors    | 4
1004             | 48    | Color    | Green
1005             | 48    | Transmsn | Manual

您可以存储(品牌,型号,年份)本表为好,但让我们说你没有。

You could store (Make, Model, Year) in this table as well, but let's say you didn't.

您是插入成为这样的事情。

You're insertion becomes something like this..

(如果你不使用 cfqueryparam ,请看看它,它可以防止SQL注入,黑客的一种常见形式。)

(If you're not using cfqueryparam, please look it up, it protects against sql injection, a common form of hacking.)

  <cfquery name="NewCar">
    insert into Cars(Make, Model, Year)
    values(<cfqueryparam value="#form.make#" cfsqltype="cf_sql_varchar">,
      <cfqueryparam value="#form.model#" cfsqltype="cf_sql_varchar">,
      <cfqueryparam value="#form.year#" cfsqltype="cf_sql_integer">)
  </cfquery>

  <cfset DeletedFields = "make,model,year,submit_button,tos_agree">

  <cfloop list="#form.fieldnames#" index="df">
    <cfif not listfind(deletedfields,df)>
      <cfquery>
        insert into CarSpecs(CarID,SpecName,SpecValue)
        values(<cfqueryparam cfsqltype="cf_sql_integer" value="#NewCar.generatedKey#">,
            <cfqueryparam cfsqltype="cf_sql_varchar" value="#fn#">,
            <cfqueryparam cfsqltype="cf_sql_varchar" value="#form[fn]#">)
      </cfquery>
    </cfif>
  </cfloop>

有几个简单的方法,让你刚插入的记录的ID(#NewCar.generatedkey#)。 这里是一个简短的文章就可以了,如果你不熟悉。

There are a few easy ways to get the id of the record you just inserted (#NewCar.generatedkey#). Here's a short article on it if you're unfamiliar.

最好的办法是插入到不同的行,因为我已经以实例阐述。随后,单独的列会比插入作为大宗更好。

The best way is inserting into separate rows as I've demostrated. Following that, separate columns would be better than inserting as a bulk.

唯一的好处插入一个大部分是很容易的,仅此而已。

The only benefit to inserting as a bulk is it's easy, that's it.

的缺点,但是,是多方面的。

The downsides, however, are numerous.

要选择的任何数据,你必须为

To select any of the data, you have to either


  • 选择所有的数据。 - 不必要的开销

  • 尝试并使用SQL来分析数据 - 不必要的开销

Intertable查询(加入)的基础上这一领域将是一个巨大的头痛。

Intertable queries (joins) based on this field are going to be a huge headache.

因此​​,假设你设计的东西像我例子。你可以选择这样的车的所有细节。

So suppose you devised something like my example above. You could select all the details for a car like this.

<cfoutput query="CarDetails" group="carID">#Make# #Model# #Year#<br /><br />
  <cfoutput>#replace(specname,"_"," ","ALL")#: <input type="text" name="#specname#" value="#htmleditformat(specvalue)#" /> <br /></cfoutput>
</cfoutput>

这篇关于解析数组,其中包含输入名称和值回形式为只读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆