Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFSET on Conditional Form

Status
Not open for further replies.

NeoTurtle

Programmer
Aug 25, 2000
38
US
Hi everyone. I'm having a bit of a problem with this:

I've made a conditional form to Update or Add a category. I've tried just about everything. I'm using ColdFusion 4.0. This is what I have:

<CFIF IsDefined(&quot;CatID&quot;)>
<CFSET NewCat=&quot;No&quot;>

<CFELSE>
<CFSET NewCat=&quot;Yes&quot;>
</CFIF>

<CFIF NewCat>
<CFSET PageTitle = &quot;JinMAU - Add a Category&quot;>
<CFSET ButtonText = &quot; A d d &quot;>
<CFSET Category = &quot; &quot;>

<CFELSE>
<CFQUERY DATASOURCE=&quot;jinmau&quot; NAME=&quot;Edit&quot;>
SELECT CatID, Category
FROM Categories
WHERE CatID=#CatID#
</CFQUERY>
<CFSET PageTitle = &quot;JinMau - Update a Category&quot;>
<CFSET ButtonText = &quot; U p d a t e &quot;>
<CFSET Category = &quot;Trim(Categories.Category)&quot;>
</CFIF>

<CFOUTPUT QUERY=&quot;Edit&quot;>

The error occurs when I try to add a new category. Tells me that the QUERY is not named. So I just put <CFOUTPUT> without the query name. Then I get an &quot;error&quot; when trying to update a category. Well, not a error, but I get the words Trim(Categories.Category) instead of the value of the field. I tried putting the <CFOUTPUT> in the <CFIF NewCat> and <CFOUTPUT QUERY=&quot;Edit&quot;> in the <ELSE> with no success.

Thanks in advance,
-NeoTurtle
 
Hi!

I modified your code a bit and you will have to put the CFOUTPUT into the else statement. I fixed also that line that was wrong: <CFSET Category = Trim(Categories.Category)>


<CFIF IsDefined(&quot;CatID&quot;)>
<CFSET NewCat=&quot;No&quot;>

<CFELSE>
<CFSET NewCat=&quot;Yes&quot;>
</CFIF>

<CFIF NewCat>
<CFSET PageTitle = &quot;JinMAU - Add a Category&quot;>
<CFSET ButtonText = &quot; A d d &quot;>
<CFSET Category = &quot; &quot;>

<CFELSE>
<CFQUERY DATASOURCE=&quot;jinmau&quot; NAME=&quot;Edit&quot;>
SELECT CatID, Category
FROM Categories
WHERE CatID=#CatID#
</CFQUERY>
<CFSET PageTitle = &quot;JinMau - Update a Category&quot;>
<CFSET ButtonText = &quot; U p d a t e &quot;>
<CFSET Category = Trim(Categories.Category)>
[tab][tab]<CFOUTPUT QUERY=&quot;Edit&quot;>
[tab][tab]...
[tab][tab]</CFOUTPUT>
</CFIF>


 
Thanks for your reply onirike. I'm still having problems with the code. The error is:

Invalid end tag on line 126 at position 1. Cold Fusion was looking at the following text:

</CFOUTPUT>

The likely cause of the problem is the presence of an end tag without a corresponding start tag


That's because I already have a </CFOUTPUT> at the end of the page. I took out the </CFOUTPUT> in the ELSE tag. Then I get this:

An extraneous end tag </CFOUTPUT> has been encountered at document position (124:1) to (124:11). End tags cannot be present in CFML templates without a matching start tag.

The last successfully parsed CFML construct was static text occupying document position (117:53) to (123:1).


Also, the reason I used &quot;Trim(Categories.Category)&quot; is because if I don't use the quotes, the INPUT TEXT BOX puts in Trim(Categories.Category) as the defaul text instead of the actual value. Perhaps posting the entire page and the page leading to the troubled page might help:

The page leading to the troubled page


<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>

<CFIF NOT ISDEFINED(&quot;session.logged&quot;)>
<CFLOCATION URL=&quot;login.cfm&quot;>
</CFIF>

<CFQUERY DATASOURCE=&quot;jinmau&quot; NAME=&quot;categories&quot;>
SELECT Category, CatID
FROM Categories
ORDER BY Category
</CFQUERY>

<HTML>
<HEAD>
<LINK REL=&quot;stylesheet&quot; HREF=&quot;../JinMAU.css&quot; TYPE=&quot;text/css&quot;>
<TITLE>JinMAU - Edit Web Directory</TITLE>
</HEAD>

<!-- Highlights links on mouse over | IE | -->
<STYLE>
<!--
a:hover {
color : #0000FF;
background-color : #FFFF00;
text-decoration : none;
}
-->
</STYLE>

</HEAD>

<BODY>
<BR><BR>

<TABLE WIDTH=&quot;80%&quot; CELLSPACING=&quot;0&quot; CELLPADDING=&quot;0&quot; ALIGN=&quot;CENTER&quot; NOWRAP STYLE=&quot;border-left-width: thin; border-right-width: thin; border-top-width: thin; border-bottom-width: thin; border-width: thin; border-color: 000080; border-style: solid;&quot; CLASS=&quot;JinMAU&quot;>
<TR>
<TD WIDTH=&quot;10%&quot; ALIGN=&quot;CENTER&quot; BGCOLOR=&quot;000080&quot;>
<A HREF=&quot;editcat.cfm?CFID=#CFID#&CFTOKEN=#CFTOKEN#&quot;>
<FONT COLOR=&quot;FFFFFF&quot;>
<B>
Add Category
</B>
</FONT>
</A>
</TD>
<TD COLSPAN=&quot;2&quot; BGCOLOR=&quot;000080&quot;>
<FONT SIZE=&quot;+2&quot; COLOR=&quot;FFFFFF&quot;>
<B>
Edit the Web Directory:
</B>
</FONT>
</TD>
</TR>
<CFOUTPUT QUERY=&quot;categories&quot;>
<TR>
<!--- TD BGCOLOR=&quot;###Iif(((CurrentRow MOD 2) is 0),de('FFFFFF'),de('CCCCCC'))#&quot;
alternates cell colors between light gray and white --->
<TD ALIGN=&quot;CENTER&quot; BGCOLOR=&quot;###Iif(((CurrentRow MOD 2) is 0),de('FFFFFF'),de('CCCCCC'))#&quot; WIDTH=&quot;10%&quot;>
<A HREF=&quot;editcat.cfm?CatID=#CatID#&CFID=#CFID#&CFTOKEN=#CFTOKEN#&quot; STYLE=&quot;text-decoration: none&quot;>
Edit
</A>
</TD>
<TD BGCOLOR=&quot;###Iif(((CurrentRow MOD 2) is 0),de('FFFFFF'),de('CCCCCC'))#&quot; WIDTH=&quot;60%&quot; CLASS=&quot;JinMAU&quot;>
#Category#
</TD>
<TD ALIGN=&quot;CENTER&quot; BGCOLOR=&quot;###Iif(((CurrentRow MOD 2) is 0),de('FFFFFF'),de('CCCCCC'))#&quot; WIDTH=&quot;10%&quot;>
<A HREF=&quot;delcat.cfm?CatID=#CatID#&CFID=#CFID#&CFTOKEN=#CFTOKEN#&quot; STYLE=&quot;text-decoration: none&quot;>
Delete
</A>
</TD>
</TR>
</CFOUTPUT>
</TABLE>
<BR>
<BR>

</BODY>
</HTML>

This is the page that's giving me problems.
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>

<CFIF NOT ISDEFINED(&quot;session.logged&quot;)>
<CFLOCATION URL=&quot;login.cfm&quot;>
</CFIF>

<CFIF IsDefined(&quot;CatID&quot;)>
<CFSET NewCat=&quot;No&quot;>

<CFELSE>
<CFSET NewCat=&quot;Yes&quot;>
</CFIF>

<CFIF NewCat>
<CFSET PageTitle = &quot;JinMAU - Add a Category&quot;>
<CFSET ButtonText = &quot; A d d &quot;>
<CFSET Category = &quot; &quot;>

<CFELSE>
<CFQUERY DATASOURCE=&quot;jinmau&quot; NAME=&quot;Edit&quot;>
SELECT CatID, Category
FROM Categories
WHERE CatID=#CatID#
</CFQUERY>
<CFSET PageTitle = &quot;JinMau - Update a Category&quot;>
<CFSET ButtonText = &quot; U p d a t e &quot;>
<CFSET Category = Trim(Categories.Category)>
<CFOUTPUT QUERY=&quot;Edit&quot;>
</CFIF>



<HTML>

<HEAD>
<LINK REL=&quot;stylesheet&quot; HREF=&quot;../JinMAU.css&quot; TYPE=&quot;text/css&quot;>
<TITLE>#PageTitle#</TITLE>

<!-- Highlights links on mouse over | IE | -->
<STYLE>
<!--
a:hover {
color : 0000FF;
background-color : FFFF00;
text-decoration : none;
}
-->
</STYLE>
</HEAD>

<BODY>

<CFIF NewCat IS &quot;No&quot;>
<INPUT TYPE=&quot;HIDDEN&quot; NAME=&quot;CatID&quot; VALUE=&quot;#CatID#&quot;>
</CFIF>

<FORM ACTION=&quot;rencat.cfm?CFID=#CFID#&CFTOKEN=#CFTOKEN#&quot; METHOD=&quot;POST&quot;>

<TABLE WIDTH=&quot;60%&quot; BORDER=&quot;0&quot; CELLSPACING=&quot;0&quot; CELLPADDING=&quot;0&quot; ALIGN=&quot;CENTER&quot;>
<TR>
<TD WIDTH=&quot;10%&quot;>
</TD>
<TD COLSPAN=&quot;2&quot; ALIGN=&quot;CENTER&quot; BGCOLOR=&quot;000080&quot;>
<FONT FACE=&quot;&quot; SIZE=&quot;+1&quot; STYLE=&quot;font-weight: bold;&quot; COLOR=&quot;FFFFFF&quot;>
Edit Category
</FONT>
</TD>
<TD WIDTH=&quot;10%&quot;>
</TD>
</TR>
<TR>
<TD WIDTH=&quot;10%&quot;>
 
</TD>
<TD WIDTH=&quot;40%&quot;>
 
</TD>
<TD WIDTH=&quot;40%&quot;>
 
</TD>
<TD WIDTH=&quot;10%&quot;>
 
</TD>
</TR>
<CFIF NewCat IS &quot;No&quot;>
<TR>
<TD WIDTH=&quot;10%&quot;>
</TD>
<TD WIDTH=&quot;40%&quot;>
Old Name:
</TD>
<TD WIDTH=&quot;40%&quot;>
#Category#
</TD>
<TD WIDTH=&quot;10%&quot;>
</TD>
</TR>
</CFIF>
<TR>
<TD WIDTH=&quot;10%&quot;>
</TD>
<TD WIDTH=&quot;40%&quot;>
New Name:
</TD>
<TD WIDTH=&quot;40%&quot;>
<INPUT TYPE=&quot;TEXT&quot; NAME=&quot;Category&quot; VALUE=&quot;#Category#&quot;>
</TD>
<TD WIDTH=&quot;10%&quot;>
</TD>
</TR>
<TR>
<TD WIDTH=&quot;10%&quot;>
</TD>
<TD WIDTH=&quot;10%&quot;>
</TD>
<TD WIDTH=&quot;40%&quot;>
<INPUT TYPE=&quot;SUBMIT&quot; VALUE=&quot;#ButtonText#&quot;>
</TD>
<TD WIDTH=&quot;10%&quot;>
</TD>
<TD WIDTH=&quot;10%&quot;>
</TD>
</TR>
</CFOUTPUT>
</TABLE>

</FORM>

</BODY>
</HTML>

Once again . . . thanks in advance.
-NeoTurtle
 
Hi!

I fixed some stuff once again!
Not sure if it will fix everything but try it!

Chris

fixed code

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>

<CFIF NOT ISDEFINED(&quot;session.logged&quot;)>
<CFLOCATION URL=&quot;login.cfm&quot;>
</CFIF>

<CFIF IsDefined(&quot;CatID&quot;)>
<CFSET NewCat=&quot;No&quot;>

<CFELSE>
<CFSET NewCat=&quot;Yes&quot;>
</CFIF>

<CFIF NewCat>
<CFSET PageTitle = &quot;JinMAU - Add a Category&quot;>
<CFSET ButtonText = &quot; A d d &quot;>
<CFSET Category = &quot; &quot;>

<CFELSE>
<CFQUERY DATASOURCE=&quot;jinmau&quot; NAME=&quot;Edit&quot;>
SELECT CatID, Category
FROM Categories
WHERE CatID=#CatID#
</CFQUERY>
<CFSET PageTitle = &quot;JinMau - Update a Category&quot;>
<CFSET ButtonText = &quot; U p d a t e &quot;>
<CFSET Category = Trim(Edit.Category)>
</CFIF>

<CFOUTPUT>

<HTML>

<HEAD>
<LINK REL=&quot;stylesheet&quot; HREF=&quot;../JinMAU.css&quot; TYPE=&quot;text/css&quot;>
<TITLE>#PageTitle#</TITLE>

<!-- Highlights links on mouse over ¦ IE ¦ -->
<STYLE>
<!--
a:hover {
color : 0000FF;
background-color : FFFF00;
text-decoration : none;
}
-->
</STYLE>
</HEAD>

<BODY>

<CFIF NewCat IS &quot;No&quot;>
<INPUT TYPE=&quot;HIDDEN&quot; NAME=&quot;CatID&quot; VALUE=&quot;#CatID#&quot;>
</CFIF>

<FORM ACTION=&quot;rencat.cfm?CFID=#CFID#&CFTOKEN=#CFTOKEN#&quot; METHOD=&quot;POST&quot;>

<TABLE WIDTH=&quot;60%&quot; BORDER=&quot;0&quot; CELLSPACING=&quot;0&quot; CELLPADDING=&quot;0&quot; ALIGN=&quot;CENTER&quot;>
<TR>
<TD WIDTH=&quot;10%&quot;>
</TD>
<TD COLSPAN=&quot;2&quot; ALIGN=&quot;CENTER&quot; BGCOLOR=&quot;000080&quot;>
<FONT FACE=&quot;&quot; SIZE=&quot;+1&quot; STYLE=&quot;font-weight: bold;&quot; COLOR=&quot;FFFFFF&quot;>
Edit Category
</FONT>
</TD>
<TD WIDTH=&quot;10%&quot;>
</TD>
</TR>
<TR>
<TD WIDTH=&quot;10%&quot;>

</TD>
<TD WIDTH=&quot;40%&quot;>

</TD>
<TD WIDTH=&quot;40%&quot;>

</TD>
<TD WIDTH=&quot;10%&quot;>

</TD>
</TR>
<CFIF NewCat IS &quot;No&quot;>
<TR>
<TD WIDTH=&quot;10%&quot;>
</TD>
<TD WIDTH=&quot;40%&quot;>
Old Name:
</TD>
<TD WIDTH=&quot;40%&quot;>
#Category#
</TD>
<TD WIDTH=&quot;10%&quot;>
</TD>
</TR>
</CFIF>
<TR>
<TD WIDTH=&quot;10%&quot;>
</TD>
<TD WIDTH=&quot;40%&quot;>
New Name:
</TD>
<TD WIDTH=&quot;40%&quot;>
<INPUT TYPE=&quot;TEXT&quot; NAME=&quot;Category&quot; VALUE=&quot;#Category#&quot;>
</TD>
<TD WIDTH=&quot;10%&quot;>
</TD>
</TR>
<TR>
<TD WIDTH=&quot;10%&quot;>
</TD>
<TD WIDTH=&quot;10%&quot;>
</TD>
<TD WIDTH=&quot;40%&quot;>
<INPUT TYPE=&quot;SUBMIT&quot; VALUE=&quot;#ButtonText#&quot;>
</TD>
<TD WIDTH=&quot;10%&quot;>
</TD>
<TD WIDTH=&quot;10%&quot;>
</TD>
</TR>
</CFOUTPUT>
</TABLE>

</FORM>

</BODY>
</HTML>

 
Thanks a lot Chris!! Works great!! Now I need to start a new thread regarding DarkMan's Login in page code . . . I think it's not secure.

-NeoTurtle
 
Never mind about DarkMan's Login page . . . I thought I could access my secured pages with ?CFID= at the end, it could it be that the session was still alive. I'm going to keep trying to break into my page. =)

Thanks again,
NeoTurtle
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top