Back to 2001 Conference Presentations
HighEdWeb Elections Using ColdFusion
Lucy Walker
SUNY New Paltz
Web Programmer and PC Support
Lucy@newpaltz.edu

Cold Fusion References

http://www.cfvault.com/ - some beginner/intermediate tutorials

http://www.houseoffusion.com/ - sign up for the CF-TALK mailing list if you want to be inundated with email messages that are sometimes very helpful. (You can also subscribe to digest mode and get everything in just one message a day).

http://www.allaire.com/ - Support for Cold Fusion is still found on the Allaire website, not Macromedia's. There is also the Developer's Exchange where you can sometimes find code for free.

http://www.sys-con.com/coldfusion/ - Cold Fusion Developer's Journal. Many great articles, you need to subscribe to the magazine to read all of them but you can access a few without being a subscriber.


What is Cold Fusion?

What you need Why we chose ColdFusion Some of our CF Sites

ColdFusion Markup Language

Database Variables
HighEdWeb Elections HighEdWeb database

Assigning Login Codes


Get list of members - ID only:

SQL Select Statement Format
Select fieldname
>From tablename
Where criteria
SQL Update Statement
Update tablename
Set fieldname=value
Where criteria

CFOUTPUT <CFOUTPUT query="getID"> #ID#
</CFOUTPUT>

<CFSET...> creates a variable and assigns a value to it

<CFSET code=RandRange(1,10000)>
Generates a random number between 1 and 10,000 and puts the value in #code#


Final Cold Fusion Code

<CFOUTPUT query="getID">
<CFSET code=RandRange(1,10000)>
<CFQUERY NAME="updatecode" DATASOURCE="highedweb">
UPDATE members
SET code=#code#
WHERE ID=#ID#
</CFQUERY>
</CFOUTPUT>


Mailing Codes to Members

Get member name, email addresses and codes:

<cfquery name="userquery" datasource="highedweb">
select name, email, code
from members
order by name
</cfquery>

<cfmail query="userquery"
to="#email#"
from="walkerl@newpaltz.edu"
subject="HighEdWeb Elections">
#name#,
Your code is #code#
</CFMAIL>


Voting

signin.cfm -> vote.cfm -> insertvote.cfm

Sign In to Vote (signing.cfm)

If the user does not enter a code, they will see the message in "value"

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

Enter your Election Code to vote:
<input type="Text" name="code" size=5>
<input type="hidden" name="code_required" size=5 value="You must enter a valid election code in order to cast your vote.">
<input type="submit" value="Sign In">
</form>

CFIF tag (signin.cfm)

<CFIF condition> code
<CFELSEIF condition> code
<CFELSE>
</CFIF>
Comparisons for condition are EQ, GT, LT, ...

Voting (vote.cfm)

<CFPARAM name="form.code" default="0">

<CFIF ISNumeric(form.code)>
   <CFSET newcode=form.code>
<CFELSE> <CFSET newcode=0>
</CFIF>

Check Sign-in Code in Members table:

<CFQUERY NAME="checkcode" DATASOURCE="highedweb">
   SELECT voted
   FROM members
   WHERE code=#newcode#
</CFQUERY>

Check if the code entered was found in the database: (nameofquery.recordcount)

<CFIF #checkcode.recordcount# IS 0>
   The election code you entered is not valid. Please <a href="signin.cfm">try again</a>.

Check if this member already voted:

<CFELSEIF #checkcode.voted# NEQ 0>
   The election code you entered has been used already. Try entering your <a href="signin.cfm">code again</a>

Mark as Signed In (vote.cfm)
Mark this member as having signed in:

<CFELSE>
   <CFQUERY NAME="marksignedin" DATASOURCE="highedweb">
     UPDATE members
     SET loggedin=-1
     WHERE code=#form.code#
</CFQUERY>

Getting List of Nominees (vote.cfm)

   <cfquery name="showprez" datasource="highedweb">
     SELECT *
     FROM nominations
     ORDER BY position, nominee asc
   </cfquery>

Form fields for voting (vote.cfm)

   <cfoutput query="showprez" group="position">
   #Position#
   <cfoutput><input type="radio" name="#position" value="#nominee#"> #nominee# (#university#)
   </cfoutput>
   </cfoutput>

Insert Vote (insertvote.cfm)
<CFINSERT> tag (insertvote.cfm)
If the names of the form fields match the names of the fields in the database, you can use CFINSERT instead of <CFQUERY> with an SQL Insert statement
<cfinsert datasource="highedweb"
tablename="elections"
formfields="president, vice_president, secretary, treasurer, president_other, vp_other, secretary_other, treasurer_other">

NOTE: There is an article on the Macromedia(Allaire) website that recommends you DON'T use cfinsert.

Mark member as "voted"

<CFQUERY NAME="markvoted" DATASOURCE="highedweb">

UPDATE members
SET voted=-1
WHERE code=#form.code#

</CFQUERY>

Back to 2001 Conference Presentations