Database Reference
In-Depth Information
6. Create a form submission button and terminate the form:
print
br
(),
submit
(
-
name
=>
"choice"
,
-
value
=>
"Submit Form"
),
end_form
();
The same general procedure applies to other APIs. For example, in a JSP page, fetch the
record to be edited and extract its contents into scalar variables like this:
<c:set
var=
"id"
value=
"1"
/>
<sql:query
dataSource=
"${conn}"
var=
"rs"
>
SELECT
id, color, size, accessories,
cust_name, cust_street, cust_city, cust_state
FROM cow_order WHERE id = ?
<sql:param
value=
"${id}"
/>
</sql:query>
<c:set
var=
"row"
value=
"${rs.rows[0]}"
/>
<c:set
var=
"id"
value=
"${row.id}"
/>
<c:set
var=
"color"
value=
"${row.color}"
/>
<c:set
var=
"size"
value=
"${row.size}"
/>
<c:set
var=
"accessories"
value=
"${row.accessories}"
/>
<c:set
var=
"cust_name"
value=
"${row.cust_name}"
/>
<c:set
var=
"cust_street"
value=
"${row.cust_street}"
/>
<c:set
var=
"cust_city"
value=
"${row.cust_city}"
/>
<c:set
var=
"cust_state"
value=
"${row.cust_state}"
/>
Then use the values to initialize the various form elements, such as:
• The hidden field for the ID value:
<input
type=
"hidden"
name=
"id"
value=
"<c:out value="
${id}"
/>
"/>
• The
color
pop-up menu:
<sql:query
dataSource=
"${conn}"
var=
"rs"
>
SELECT color FROM cow_color ORDER BY color
</sql:query>
<br
/>
Cow color:
<br
/>
<select
name=
"color"
>
<c:forEach
items=
"${rs.rows}"
var=
"row"
>
<option
value=
"<c:out value="
${row.color}"
/>
"
<c:if
test=
"${row.color == color}"
>
selected="selected"
</c:if>
>
<c:out
value=
"${row.color}"
/></option>
</c:forEach>
</select>
• The
cust_name
text field:
<br
/>
Customer name:
<br
/>
<input
type=
"text"
name=
"cust_name"