Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Coldfusion 如何获取选定的值_Coldfusion_Coldfusion 9 - Fatal编程技术网

Coldfusion 如何获取选定的值

Coldfusion 如何获取选定的值,coldfusion,coldfusion-9,Coldfusion,Coldfusion 9,我无法确定如何循环查询questionType并获取所选questionType值。根据所选的问题类型,我必须为多选项问题添加答案,如在“选择正确答案”中,我们提供了四个选项,其中一个选项必须选择为正确答案 我曾尝试使用cfswitch,但似乎不起作用: <html> <head> <script src="http://code.jquery.com/jquery-latest.js"></script></head> <b

我无法确定如何循环查询questionType并获取所选questionType值。根据所选的问题类型,我必须为多选项问题添加答案,如在“选择正确答案”中,我们提供了四个选项,其中一个选项必须选择为正确答案

我曾尝试使用
cfswitch
,但似乎不起作用:

<html>
  <head> <script src="http://code.jquery.com/jquery-latest.js"></script></head>
<body>
<cfoutput>


    <cfif not IsDefined('rc.questionType')>
        <form class="form form-horizontal" action="#buildUrl('question.new')#" method="post">
            <input type="hidden" name="surveyId" value="#rc.surveyId#">
                <fieldset>

                <div class="control-group">
                <label class="control-label" for="questiontype">Question type</label>
                    <div class="controls">
                    <select name="questionType" onchange="this.form.submit()">
                        <option value="0" >Select question type</option>
                    <cfloop query="rc.types">
                        <option value="#id#">#name#</option>
                    </cfloop> 
                    </select>
                    </div>
                </div> 
                </fieldset>
        </form> 

    <!--- if question type is defined, display question form --->
    <cfelse>
        <form class="form form-horizontal" action="#buildUrl('question.save')#" method="post">
            <input type="hidden" name="id" value="0">
            <input type="hidden" name="surveyId" value="#rc.data.fksurveyId#">
            <input type="hidden" name="questionTypeId" value="#rc.data.fkquestionTypeId#">
            <input type="hidden" name="rank" value="#rc.data.rank#">



            <fieldset>

            <div class="control-group">
            <label class="control-label" for="question">Question</label>
                <div class="controls">
                    <input class="input-xxlarge" type="text" name="question" id="question" required="true" placeholder="write your question">
                </div>
            </div>

            <div class="control-group">
            <label class="control-label" for="Required">Required</label>
                <div class="controls">
                <select name="Required">
                    <option value="1" selected>Yes</option>
                    <option value="0">No</option>
                </select>
                </div>
            </div>                 



            <!--- question arguments for selected type, this will be for multioption questions --->

           <!--- <cfif rc.questiontype is "multiple choice (single selection),Multiple Choice (Multi Selection) with Other,Multiple Choice (Single Selection) with Other,Multiple Choice (Multi Selection)"> --->
           <cfswitch expression="#rc.questiontypeid#">
                <cfcase value="multiple choice (single selection),Multiple Choice (Multi Selection) with Other,Multiple Choice (Single Selection) with Other,Multiple Choice (Multi Selection)">
                 <div class="control-group">
                    <label class="control-label" for="answer">Answer</label>
                      <div class="controls">
                         <input class="input-xxlarge" type="text" name="new_answer" id="new_answer">
                      </div>
                </div>

               <div class="control-group">
                   <label class="control-label" for="rank">rank</label>
                      <div class="controls">
                         <input class="input-mini" type="text" name="rank" id="rank">
                     </div>
               </div>


                <div class="control-group">
                    <label class="control-label" for="answer">Answer</label>
                      <div class="controls">
                         <input class="input-xxlarge" type="text" name="new_answer" id="new_answer">
                      </div>
                </div>

               <div class="control-group">
                   <label class="control-label" for="rank">rank</label>
                      <div class="controls">
                         <input class="input-mini" type="text" name="rank" id="rank">
                     </div>
               </div>
          </cfcase>
        </cfswitch>




            <!---  --->
            <div class="form-actions">
                <button type="submit" class="btn btn-primary">Save</button>
                <a href="#buildUrl(action='admin:question.list', querystring='surveyid=#rc.surveyId#')#" class="btn">Cancel</a>
            </div>
            </fieldset>
        </form> 
    </cfif>
<cfdump var="#rc#">

</cfoutput>
</body>
</html>

问题类型
选择问题类型
#名字#
问题:
要求的
对
不
答复
等级
答复
等级
拯救
这是我的控制器添加新问题的方法:

<cffunction name="new" returntype="void" access="public">
        <cfargument name="rc" type="struct" required="true">
        <!---call service to get the textfields, checkboxes etc,. based on questiontype selection --->
        <!--- call service to get question types for select box --->
        <cfset rc.types = getQuestionService().types()> 
        <cfset rc.action = 'New Question'>
        <!--- if user select question type --->
        <cfif isdefined('arguments.rc.questionType')>
            <cfset rc.data = getQuestionService().new(arguments.rc.surveyId, arguments.rc.questionType)>
        </cfif> 
    </cffunction>


我一页有两张表格。在第一种形式中,我选择问题类型。根据所选问题类型,我必须显示添加问题表单

由于开关表达式设置为
rc.questiontypeid
,因此大小写值应为可能的
rc.questiontypeid
,而不是问题类型名称。

要确保我正在阅读此代码的工作原理:

1.这是一个创建问题的表单,而不是回答问题的表单
2.rc是一个以基本问题定义为键的结构,您还有其他现有代码确保rc结构存在于该页面上
(我会使用structKeyExists(rc,“questionType”),而不是定义(“rc.questionType”),但这是一个完全不同的讨论。
3.当您更改问题类型的值时,该字段将被提交回,其他代码将创建并填充rc struct的questionType键。因此isDefined('rc.questionType')现在应为TRUE(将您移动到cfelse块)。
4.现在,您将返回到同一页面,其中包含一个字段,用于输入问题,无论该问题是否为必填项,并且您将根据问题类型查找答案输入框

如果所有这些假设都是正确的,那么这就是你需要循环选择答案的地方。cfswitch/cfcase是正确的,但其中一些多选选项需要稍微不同的处理。带有“其他”的选项选项在此端和答案跟踪端需要稍微多一些处理。您必须为选中的答案添加一个文本框

因此,您需要对rc结构中的问题进行更多的定义。您需要跟踪哪一个是正确答案(一个简单的复选框)。如果要允许动态数量的多选答案,则需要跟踪所需答案的数量。如果跟踪答案是否为“其他”,甚至可以将这些多选答案选项放在一起。这还允许您拥有多个“其他”-在多选选项中键入选项。当然,这会将您对这是否是一个多选问题的选择减少到只有一个,即“多选”。让答案确定这是单选还是“其他”选择。如果你想使用单选按钮而不是复选框来选择单个选项,你所要做的就是计算问题的答案。然后你可以分别考虑每个基本的问题类型

更好地跟踪答案(正确选项和“其他”选项)的代码也需要重新提取,可能是在getQuestionService()函数中,我假设您正在提取问题定义并填充rc结构

您是否计划使用此表单作为插入,或者这只是一个插入,您将在其他地方更新/编辑问题

不管怎样,回到你最初的问题。我建议的第一件事是在页面顶部也cfdump rc struct。看看你最初使用的是什么数据

在你需要添加答案的地方,cfswitch是正确的方法。你可能没有在这里匹配任何案例。在这里输出rc.questionTypeID以查看你的值。我将使用整数ID作为问题类型,而不是问题类型的名称。它将提供更快、更精确的处理。当你得到正确的c因此,您需要在此处循环您的答案


要选择正确的选项,只需添加一个selected=“selected”或checked=“checked”(取决于输入类型)在cfif中,检查当前答案是否正确。

你昨天不是已经问过这个问题了吗?是的,我问过了,但有人告诉我添加条件逻辑,然后再发布。我就是这么做的。希望你不介意。没关系,我不确定我是不是疯了。为什么你有两种形式?我有两种形式e页,第一种形式我是se