944,128 Members | Top Members by Rank

Ad:
  • ColdFusion Discussion Thread
  • Unsolved
  • Views: 2196
  • ColdFusion RSS
May 17th, 2006
0

never learned by e.g. - its horrible form - help?

Expand Post »
please take a look at some of these code snippets i've taken from what i'm currently working on in CFMX 6.1. i'll explain briefly the context and purpose for each. i apologize if this is 'too verbose'.

*[php]<cfset qone = "First Name:">
<cfset qtwo = "Last Name:">
<cfset qthree = "Choose a Password:">
<cfset qfour = "Valid e-mail (post grad):">[/php] ** this sets the variables for an output later (see next snippet) to indicate which form fields were empty on posting **

<font color="MAROON">[php]<cfif isdefined("FORM.op")> // <!--- FORM HAS BEEN SUBMITTED --->
<cfset variables.emptymsg = "<ul>">

<cfif FORM.name_first EQ ""> // <!--- IF THE FIRST FIELD HOLDS A VALUE THEN... --->
<cfset variables.emptymsg = variables.emptymsg & "<li>#VARIABLES.qone#</li>">
<cfset variables.resub = 1>
<cfelse>
// <!--- <cfset variables.name_first = #Form.name_first#> --->
</cfif>
<cfif FORM.name_last EQ "">
<cfset variables.emptymsg = variables.emptymsg & "<li>#VARIABLES.qtwo#</li>">
<cfset variables.resub = variables.resub + 1>
<cfelse>
// <!--- <cfset variables.last = #Form.name_last#> --->
</cfif>[/php] ** here is my attempt at form validation -- the form posts back to the same page-- although i'm not currently using getcurrenttemplatepath() because it gives me a C:\folder\file.cfm string instead of *http://localhost/file.cfm*
** as you can see, variables.emptymsg (2nd line above) is established so it can be used to report the missing form fields
** variables.emptymsg concatenated on each field until form end, ultimately creating a UL for output indicating all empty fields this submission.
** variables.resub is a simple counter (in php, i'd use X++). is there an easier way?

[php] // <!--- CREATE CFSWITCH HERE FOR VARIABLES.CORDIAL --->
<cfif isdefined("variables.resub")> // <!--- RESUB IS THE NUMERIC COUNTER --->
<cfswitch expression="#variables.resub#"> // <!--- WE ARE TESTING AGAINST THIS VALUE -->
<cfcase value="GTE 1"> // A TEST CASE --->
<cfset variables.cordial = "You failed to submit the following fields:" & "#variables.emptymsg#">
</cfcase>
<cfcase value="">
<cfset variables.cordial = "Thank you for providing your information">
</cfcase>[/php]
** i'm testing for the counter variable here. this sets the conditional output for the user, variables.cordial .

<font color="#000080">[php]<p>
<cfoutput>#variables.cordial#</cfoutput> // <!--- A PLACE TO TEST SOME OUTPUT --->
</p>
<div class="twocolform"> // <!--- THE FORM BEGINS --->
<cfform method="post" action="#getcurrenttemplatepath()#">
<ol class="orderleft"><cfoutput>
<li class="decimal">First Name:<br /><cfinput type="text" name="name_first" value="#variables.name_first#" /></li>[/php]
** and finally, showing you how i've done the FORM so that the fields are re-populated on the second time around (if other fields were empty)

so, is everything being done the HARD way, or what? i look forward to a reply, and hopefully someone might have a suggestion for improvement-- or even a link to a resource which might help me to get through this a little better?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
OrangeSunshine is offline Offline
7 posts
since May 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ColdFusion Forum Timeline: Admin Login
Next Thread in ColdFusion Forum Timeline: Who's online





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC