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

Reply

Join Date: May 2006
Posts: 7
Reputation: OrangeSunshine is an unknown quantity at this point 
Solved Threads: 0
OrangeSunshine's Avatar
OrangeSunshine OrangeSunshine is offline Offline
Newbie Poster

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

 
0
  #1
May 17th, 2006
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?
My little collection of useful stuff... if you're a newb, or even someone just starting to get into CSS and XHTML, there might be something worth looking at in there
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ColdFusion Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC