處理表單至少兩個部分,兩個部份可以是一個檔案或是寫在一起
<body>
<h2>表單留言</h2>
<form action="actionPage.cfm" method="POST">
姓名
<input name="guestName" type="Text" size="30"><br/>
e-mail
<input name="email" type="Text" size="30"><br/>
留言
<textarea name="message" cols="36" rows="5"></textarea><br/>
<input type="submit" name="Submit" value="送出">
<input type="reset" name="Reset" value="重設">
</form>
</body>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<title>確認留言</title>
<body>
<cfif IsDefined("FORM.Submit")> <!-- 如果沒有透過form page執行這個動作頁,會出現錯誤,所以用IsDefined 防範 -->
<cfoutput>
<p>#FORM.guestName# 您好: </p>
您輸入的資料如下: <br><br>
<b>姓名: </b>#FORM.guestName#<br>
<b>email: </b>#FORM.email#<br>
<b>留言內容: </b>#FORM.message#<br>
</cfoutput>
</body>
</html>
HelloWho.cfm?name=John&great=Hello
<html>
<head>
<title>Greeting the Beatles</title>
</head>
<body>
Choose a Name to greet.
<ul>
<li><a href="HelloWho.cfm?name=Paul&great=Hi">Paul</a></li>
<li><a href="HelloWho.cfm?name=John&great=Hello">John</a></li>
<li><a href="HelloWho.cfm?name=George&great=Good">George</a></li>
<li><a href="HelloWho.cfm?name=Ringo&great=Bye">Ringo</a></li>
</ul>
</body>
</html>
<cfoutput>#URL.great#</cfoutput>,<cfoutput>#URL.name#</cfoutput>, nice to see u again.
guestName=Smith&great=Hello
,不同的配對用 &
區隔guestName=Smith
的格式送出資料<cfoutput>
#URL.guestName#
</cfoutput>
<cfoutput>
#FORM.guestName#
</cfoutput>
(nternationalization)
<cfprocessingdurectuve pageencoding="big5">
<cfcontent type="text/html; charset=big5">
<cfset setEncoding("URL", "big5")>
<cfset setEncoding("Form", "big5")>
ColdFusion + Sql Query
todo_list
todo_list.cfm
add_todo_act.cfm
modify_todo_act.cfm
delete_todo_act.cfm
<cfparam name="status" default = "2">
<cfparam name="sortBy" default = "3">
<cfquery name="todo_list" datasource="">
<cfif #status# EQ 2>
select todo_id,todo_task,todo_status,todo_date
from todo_list
<cfif #sortBy# EQ 3>
order by todo_date ASC;
<cfelse>
order by todo_status;
</cfif>
<cfelse>
select todo_id,todo_task,todo_status,todo_date
from todo_list
where todo_status = #status#
<cfif #sortBy# EQ 3>
order by todo_date ASC;
</cfif>
</cfif>
</cfquery>
<cfset dataID = ValueList(todo_list.todo_id)>
<cfset dataTask = ValueList(todo_list.todo_task)>
<cfset dataStatus = ValueList(todo_list.todo_status)>
<cfset dataDate = ValueList(todo_list.todo_date)>
<cfoutput> 篩選及排序</cfoutput>
<form method = "GET" action="todo_list.cfm">
<input type = "radio" value = "2" id="all" name="status" <cfif status EQ 2>
checked = "checked"
</cfif> > all
<input type = "radio" value = "0" id="todo" name="status" <cfif status EQ 0>
checked = "checked"
</cfif>> 未完成
<input type = "radio" value = "1" id="done" name="status" <cfif status EQ 1>
checked = "checked"
</cfif>> 已完成
<select name = "sortBy">
<option value = "3" <cfif sortBy EQ 3>
selected="selected"</cfif>> 依日期排序</option>
<option value = "4" <cfif sortBy EQ 4>
selected="selected"</cfif>> 依完成狀態排序</option>
</select>
</br>
<input type="submit" value="篩選及排序">
</form>
</br>
<cfoutput> 待辦事項</cfoutput>
<form action="add_todo_act.cfm" method="POST" >
<input type="text" id="add" name = "needToDo">
<input type="submit" name="Submit" value="新增待辦事項">
</form>
</br>
<table>
<tr>
<td colspan="2" align="center" bgcolor="#FFFFFF"><font color="647bcf">待辦事項</font></td>
<td colspan="2" align="center" bgcolor="#FFFFFF"><font color="647bcf">新增日期</font></td>
<td colspan="2" align="center" bgcolor="#FFFFFF"><font color="647bcf">功能</font></td>
<td colspan="2" align="center" bgcolor="#FFFFFF"><font color="647bcf"> </font></td>
<td colspan="2" align="center" bgcolor="#FFFFFF"><font color="647bcf">狀態</font></td>
</tr>
<cfoutput>
<cfloop index = "ii" from = "1" to = #ListLen(dataID)#>
<tr>
<td colspan="2" align="center">#ListGetAt(dataTask, ii)#</td>
<td colspan="2" align="center">#ListGetAt(dataDate, ii)#</td>
<td colspan="2">
<form action="modify_todo_act.cfm" method="POST" >
<input type="button" name="beModify" value="更新狀態" onclick = "modifyStatus(#ListGetAt(dataID, ii)#, #ListGetAt(dataStatus, ii)#)">
</form>
</td>
<td colspan="2">
<form action="delete_todo_act.cfm" method="POST">
<input type="button" name="beDone" value="刪除" onclick = "deleteID (#ListGetAt(dataID, ii)#)">
</form>
</td>
<td colspan="2" align="center"><cfif #ListGetAt(dataStatus, ii)# EQ 1 >完成 <cfelse>未完成</cfif></td>
</tr>
</cfloop>
</cfoutput>
</table>
<script>
deleteID = function(dataID){
var r=confirm("確認刪除?");
if (r==true) {
location.href = "delete_todo_act.cfm?dataID=" + dataID;
}else {
};
};
modifyStatus = function(dataID, dataStatus){
if(dataStatus == "0"){
var r = confirm("你真的完成了嗎?");
if( r== true) location.href = "modify_todo_act.cfm?dataID=" + dataID + "& dataStatus=" + dataStatus;
}else{
var r = confirm("發現還有東西要弄?");
if( r== true) location.href = "modify_todo_act.cfm?dataID=" + dataID + "& dataStatus=" + dataStatus;
};
};
</script>
<cfif '#FORM.needToDo#' NEQ "">
<cfquery name="insert" datasource="#">
INSERT INTO todo_list (todo_task, todo_status)
VALUES
('#FORM.needToDo#',0);
</cfquery>
<cflocation url = "todo_list.cfm">
<cfelse>
<cflocation url = "todo_list.cfm">
</cfif>
<cfquery name="beModify" datasource="">
<cfif #URL.dataStatus# EQ false>
UPDATE todo_list
SET todo_status = '1'
WHERE todo_id = #URL.dataID#;
<cfelse>
UPDATE todo_list
SET todo_status = '0'
WHERE todo_id = #URL.dataID#;
</cfif>
</cfquery>
<cflocation url = "todo_list.cfm">
<cfquery name="beDone" datasource="#m012001_ODBC_i#">
DELETE FROM todo_list
WHERE todo_id = #URL.dataID#;
</cfquery>
<cflocation url = "todo_list.cfm">