StructInsert

Description

Inserts a key-value pair into a structure. Returns Yes if the insert was successful and No if an error occurs.

Category

Structure functions

Syntax


StructInsert(structure, key, value [, allowoverwrite ]) 

See also

StructClear, StructDelete, StructFind, StructIsEmpty, StructKeyArray, StructKeyExists, StructKeyList, StructCount, StructNew, StructUpdate, StructAppend, StructGet, StructSort, StructFindKey, StructClear

Parameters

Parameter
Description
structure
Structure to contain the new key-value pair
key
Key that contains the inserted value
value
Value to add
allowoverwrite
Optional. Whether to allow overwriting a key. Default is FALSE.

Usage

This function throws an exception if structure does not exist or if key exists and allowoverwrite is set to FALSE.

Example

<!--- This example shows how to use StructInsert . It calls the

CF_ADDEMPLOYEE tag, which uses the addemployee.cfm file. --->

<html>

<head>

<title>Add New Employees</title>

</head>



<body>

<H1>Add New Employees</H1>

<!--- Establish parms for first time through --->

<CFPARAM name = "FORM.firstname" DEFAULT = "">

<CFPARAM name = "FORM.lastname" DEFAULT = "">

<CFPARAM name = "FORM.email" DEFAULT = "">

<CFPARAM name = "FORM.phone" DEFAULT = "">

<CFPARAM name = "FORM.department" DEFAULT = ""> 



<cfif FORM.firstname EQ "">

 <P>Please fill out the form.

<cfelse>

 <cfoutput>

  <CFScript>

   employee = StructNew();

   StructInsert(employee, "firstname", FORM.firstname);

   StructInsert(employee, "lastname", FORM.lastname);

   StructInsert(employee, "email", FORM.email);

   StructInsert(employee, "phone", FORM.phone);

   StructInsert(employee, "department", FORM.department);

 </CFScript> 



 <P>First name is #StructFind(employee, "firstname")#</P>

 <P>Last name is #StructFind(employee, "lastname")#</P>

 <P>EMail is #StructFind(employee, "email")#</P>

 <P>Phone is #StructFind(employee, "phone")#</P>

 <P>Department is #StructFind(employee, "department")#</P>

 </cfoutput>



 <!--- Call the custom tag that adds employees --->

 <CF_ADDEMPLOYEE EMPINFO = "#employee#">

</cfif>



<Hr>

<form action = "structinsert.cfm" method = "post">

<P>First Name:&nbsp;

<input name = "firstname" type = "text" hspace = "30" maxlength = "30">

<P>Last Name:&nbsp;

<input name = "lastname" type = "text" hspace = "30" maxlength = "30">

<P>EMail:&nbsp;

<input name = "email" type = "text" hspace = "30" maxlength = "30">

<P>Phone:&nbsp;

<input name = "phone" type = "text" hspace = "20" maxlength = "20">

<P>Department:&nbsp;

<input name = "department" type = "text" hspace = "30" maxlength = "30">



<P>

<input type = "submit" value = "OK">

</FORM>



</body>

</html>





Banner.Novgorod.Ru