Ok, sure....The code I posted was one part of my "system" that I use for
building admin pages or order forms. I originally build this to speed up
building admin pages but found that I could use it for any form.

Forgive if I over simplify this.

Let me start on defining the problem this solves.  I build lots of admin
type pages and one thing that most admin pages do is to read data from a
database and allow you to edit the data. Then you also have the admin pages
that you use to add a new record to the database.  Some times these add or
edit pages need to have required fields.  So I all of my admin pages submit
the form data to themselves and do some processing to make sure that the
required fields are filled and if all required fields are filled it inserts
the data into the database.  If the required fields are not filled in then
the page does not insert the data, and loads the form with a required
message next to the missing fields.  

So what my UDF does is it looks for the value of the input, first in a form
var, then in a query var.  If neither the form OR query contain a value for
the input box then it is just blank.  Also, since the form submits to its
self then it will pull the value from the form and not the query after you
submit the page.

Does that help explain what this does?



Example:
<cfscript>

function smartvarText(var1) {

  if (IsDefined("form.#var1#"))

  { return #form[var1]#;

  }

else if(IsDefined(queryname &'.'& var1))

{ return Evaluate(queryname &'.'& var1);

}

return "";

}

</cfscript>

<cfparam name="queryname" default="getrecord" type="string">



<cfoutput><a href="" var</a> <a
href="" var</a></cfoutput><br>

<cfif isdefined("url.q")>

Query:

<cfset getrecord = querynew('firstname')>

<cfset queryaddrow(getrecord)>

<cfset querysetcell(getrecord,'firstname','Bob',1)>

<cfdump  var="#getrecord#">

</cfif>

<cfif isdefined("url.f")>

Form:

<cfset form.firstname = 'Ed'>

<cfdump  var="#form#">

</cfif>

<form
action=""> t>" method="post">

First Name:

<cfset variables.var= "firstname">

<input name="<cfoutput>#variables.var#</cfoutput>" type="text"
value="<cfoutput>#smartvarText(variables.var)#</cfoutput>" size="35"
maxlength="255"><br>

<input name="save" type="submit" value="Save">

</form>



Mark W. Breneman
-Cold Fusion Developer
-Network Administrator
  Vivid Media
  [EMAIL PROTECTED]
  www.vividmedia.com
  608.270.9770

-----Original Message-----
From: Tony Weeg [mailto:[EMAIL PROTECTED]
Sent: Tuesday, April 06, 2004 1:24 PM
To: CF-Talk
Subject: RE: CFIF within input

mark, im a bit interested however, im not following what ur saying...

can ya explain a bit more..?
thanks
tonyS

-----Original Message-----
From: Mark W. Breneman [mailto:[EMAIL PROTECTED]
Sent: Tuesday, April 06, 2004 1:53 PM
To: CF-Talk
Subject: RE: CFIF within input

I spend way too much time building forms, so I devised a better more
flexible way to work with inputs. (IMHO) :-)

This is function will look for a form value named "Yellow", then a query
value named "Yellow" if it does not find either, it will be blank.  This UDF
lends its self very well for adding required fields and "add / edit" admin
pages..

<cfset variables.var= "Yellow">

<input name="<cfoutput>#variables.var#</cfoutput>" type="text"
value="<cfoutput>#smartvarText(variables.var)#</cfoutput>" size="35"
maxlength="255" >

All of the outputs are and the cfset out side of the input tag to keep Dream
weaver (users) happy.

UDF:
<cfscript>

function smartvarText(var1) {

  if (IsDefined("form.#var1#"))

  { return #form[var1]#;

  }

else if(IsDefined(queryname &'.'& var1))

{ return Evaluate(queryname &'.'& var1);

}

return "";

}

</cfscript>

<cfparam name="queryname" default="NULL" type="string">

Mark W. Breneman
-Cold Fusion Developer
-Network Administrator
  Vivid Media
  [EMAIL PROTECTED]
  www.vividmedia.com
  608.270.9770

-----Original Message-----
From: Tipton, Joshua [mailto:[EMAIL PROTECTED]
Sent: Tuesday, April 06, 2004 10:46 AM
To: CF-Talk
Subject: RE: CFIF within input

<cfif isdefined("var_name")>

  _____  

From: Robert Orlini [mailto:[EMAIL PROTECTED]
Sent: Tuesday, April 06, 2004 11:34 AM
To: CF-Talk
Subject: RE: CFIF within input

Tony,

When I try this I get this error:
Parameter 1 of function IsDefined which is now "text" must be a
syntactically valid variable name

RO

-----Original Message-----
From: Tony Weeg [mailto:[EMAIL PROTECTED]
Sent: Tuesday, April 06, 2004 11:32 AM
To: CF-Talk
Subject: RE: CFIF within input

but at the same time...i would...

<cfif isDefined(side_1_comments) and len(side_1_comments)>
  <input type="text" size="95" name="side_1_comments"
value="#trim(side_1_comments)#" maxlength="100"> <cfelse>
  <input type="text" size="95" name="side_1_comments" maxlength="100">
</cfif>

just to double check, and its more read-able :)

hth
tony

-----Original Message-----
From: Tony Weeg [mailto:[EMAIL PROTECTED]
Sent: Tuesday, April 06, 2004 11:28 AM
To: CF-Talk
Subject: RE: CFIF within input

ur missing a ">"

<input type="text" size="95" name="side_1_comments" maxlength="100" <CFIF
trim(side_1_comments) NEQ ""> value="#trim(side_1_comments)#"</cfif>>

try that.

-----Original Message-----
From: Robert Orlini [mailto:[EMAIL PROTECTED]
Sent: Tuesday, April 06, 2004 11:21 AM
To: CF-Talk
Subject: CFIF within input

I want to display text in a input box's value field if there is any info in
the database. The code I'm trying is:

<input type="text" size="95" name="side_1_comments" maxlength="100" <CFIF
trim(side_1_comments) NEQ "" value="#trim(side_1_comments)#"</cfif>>

But I get an error. It seems simple, but I must be missing something I can't
see.

Any suggestion please? Thanks.

Robert O.
HWW
  _____

  _____

  _____

  _____
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to