Solved

Generating CFM pages dynamically

Posted on 2009-03-30
9
340 Views
Last Modified: 2013-12-24
i am doing something very wired here can someone guide in proper way:

i am trying to generate the page dynamically based on the countries list. like if country is iceland, a page with iceland.cfm will be generated and it will be filled with the content that i have on my cfinclude page:

here is what i am trying to do.

<cfinvoke component="#request.cfcPath#.tools" method="addnewdeal" argumentcollection="#form#"/>
      <cfset templatePage = 'makepages.cfm'>
      <cfinclude template="#templatePage#">
      <cffile action="write" file="#request.absolutePath##form.countryURL#.cfm" output="#topbar#">
MAKEPAGES.CFM full code:
 
request.abosultepath is the path which points to the files properly.
 
<cfsavecontent variable="topbar">
<cfoutput>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<cfinclude template="#request.absolutePath#meta.cfm">
<link rel="stylesheet" type="text/css" href="#request.absolutePath#style.cfm" media="screen" />
<script language="javascript1.2" src="#request.absolutePath#other/flashobject.js" type="text/javascript"></script>
<script type="text/javascript" language="JavaScript1.2" src="#request.absolutePath#stmenu.js"></script>
<script language="javascript1.2" src="#request.absolutePath#other/scroller.js"></script>
<script language="javascript1.2" src="#request.absolutePath#other/jsfile.js"></script>
<cfajaximport tags="cfform">
</head>
<Body leftmargin=0 topmargin=0 marginheight="0" marginwidth="0">
<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%">
  <tr>
  
  <td width="50%" background="#request.absolutePath#images/bg.gif"><img src="#request.absolutePath#images/px1.gif" width="1" height="1" alt="" border="0"></td>
  <td valign="bottom" background="#request.absolutePath#images/bg_left.gif"><img src="#request.absolutePath#images/bg_left.gif" alt="" width="17" height="16" border="0"></td>
  <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><img src="#request.absolutePath#images/main01.jpg" width="620" align="left" height="123"></td>
              <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="300" height="46" background="#request.absolutePath#images/fon01.gif"><a href="index.cfm"><img src="#request.absolutePath#images/but001.gif" width="67" height="46" border="0"></a><img src="#request.absolutePath#images/separator.gif" width="2" height="46"><a href="contact.cfm"><img src="#request.absolutePath#images/but002.gif" alt="Advanced Search" width="90" height="46" border="0"></a><img src="#request.absolutePath#images/separator.gif" width="2" height="46"><a href="advsearch.cfm"><img src="#request.absolutePath#images/but003.gif" alt="Contact Us" width="80" height="46" border="0"></a></td>
                  </tr>
                  <tr>
                    <td height="77" background="#request.absolutePath#images/fon02.gif"><table width="235" border="0" align="center" cellpadding="5" cellspacing="0" background="">
                        <tr>
                          <th width="45"><font color="##FFFFFF"> SEARCH</font></th>
                          <td width="139"><input type="Text" name="Input" class="textfield_effect" style="text-align:right;"></td>
                          <td width="21"><input type="submit" value="" class="searchButton" name="search"></td>
                        </tr>
                      </table></td>
                  </tr>
                </table></td>
            </tr>
          </table></td>
      </tr>
    </table>
    <table border="0" cellpadding="0" cellspacing="0" width="100%" background="">
      <tr>
        <td colspan="3"><img src="#request.absolutePath#images/px1.gif" width="1" height="1" alt="" border="0"></td>
      </tr>
      <tr>
        <td bgcolor="##CECECE" colspan="3"><img src="#request.absolutePath#images/px1.gif" width="1" height="1" alt="" border="0"></td>
      </tr>
      <tr>
        <td width="276" align="center"><div id="colorarrow_id" ></div>
          <script type="text/javascript">
var fo = new FlashObject("#request.absolutePath#other/menu.swf","colorarrow","140","180","6","##000000");
    fo.addParam("menu","true");
    fo.addParam("quality","best");
    fo.addParam("scale","noscale");
    fo.addParam("salign","LT");
    fo.addParam("wmode", "transparent");
    fo.write("colorarrow_id");
</script></td>
        <td valign="bottom"><img src="#request.absolutePath#images/e01.gif" alt="" width="2" height="226" border="0"></td>
        <td><table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td colspan="2">&nbsp;</td>
            </tr>
            <tr>
              <td><a href=""><img src="#request.absolutePath#images/b01.gif" width="243" height="40" alt="" border="0"></a></td>
              <td rowspan="5"><img src="#request.absolutePath#images/top03.gif" width="259" height="200" alt="" border="0"></td>
            </tr>
            <tr>
              <td><a href=""><img src="#request.absolutePath#images/b02.gif" width="243" height="40" alt="" border="0"></a></td>
            </tr>
            <tr>
              <td><a href=""><img src="#request.absolutePath#images/b03.gif" width="243" height="40" alt="" border="0"></a></td>
            </tr>
            <tr>
              <td><a href=""><img src="#request.absolutePath#images/b04.gif" width="243" height="40" alt="" border="0"></a></td>
            </tr>
            <tr>
              <td><a href=""><img src="#request.absolutePath#images/b05.gif" width="243" height="40" alt="" border="0"></a></td>
            </tr>
            <tr>
              <td colspan="2" align="right" class="string"><strong>#DateFormat(now(),'dddd, mmmm, dd yyyy')#</strong></td>
            </tr>
          </table></td>
      </tr>
    </table>
  <div align="center" class="dodo"><img src="#request.absolutePath#images/px1.gif" width="1" height="1" alt="" border="0"></div><br>
  <table width="100%">
    <tr>
      <td><cfinclude template="#request.absolutePath#menu.cfm"></td>
    </tr>
  </table>
  <table border="0" cellpadding="2" align="center" cellspacing="2" width="100%">
    <tr valign="top">
    
    <td width="206" align="left" valign="top"><cfinclude template="#request.absolutePath#quick.cfm"><a href="javascript:void(0);" onClick="WinOpen('tellfriend.cfm','500','500');" title="Tell Your Friends"><img title="Tell Your Friends" src="#request.absolutePath#images/tell-a-friend.gif" alt="Tell Your Friends" border="0"></a><a href="forums.cfm" target="_blank" title="Our Discussion Board"><img title="Our Discussion Board" src="#request.absolutePath#images/discussion.jpg" alt="Discussion Board" width="100" height="70" border="0"></a><br></td>
    <td>
    </cfoutput>
</cfsavecontent>
 
<cfsavecontent variable="bottombar">
</td>
    
    </tr>
    
  </table>
  <br>
  <cfinclude template="#request.absolutePath#footer.cfm">
</body>
</html>
</cfsavecontent>
 
 i am getting error: as:
 
The filename, directory name, or volume label syntax is incorrect

Open in new window

0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 24019622
First problem is that upper page can be called ONLY when it is a response page to a FORM subission.
Only when the FORM strusture is supplied you will get a Country value.
So you first have to check whether that FORM. structure is present.
Like this:
<cfif isDefined("FORM.ALLFIELDS") >
...


Next you must not use the full path to a web page part like this one:
<script language="javascript1.2" src="#request.absolutePath#other/flashobject.js" type="text/javascript"></script>
var fo = new FlashObject("#request.absolutePath#other/menu.swf","colorarrow","140","180","6","##000000");
<div align="center" class="dodo"><img src="#request.absolutePath#images/px1.gif" width="1" height="1" alt="" border="0"></div><br>
 
The correct syntax is this:
<script language="javascript1.2" src="other/flashobject.js" type="text/javascript"></script>
var fo = new FlashObject("other/menu.swf","colorarrow","140","180","6","##000000");
<div align="center" class="dodo"><img src="images/px1.gif" width="1" height="1" alt="" border="0"></div><br>
 



0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 24019697
My form Stucture passed correctly, i checked it using cfdump. 
why i am using the  #request.absolutepath#, the reason is the makepages.cfm is in the admin folder and what the contents i have in the makepages.cfm are outside the admin folder, i mean outside the admin folder but in other folders, so i am trying to give the abosolute path to make it work anyhow.
path goes correctas:

c:\inetpub\wwwroot\educationconsulatant\others\menu.swf

0
 
LVL 2

Expert Comment

by:albrandwood
ID: 24020552
first, as Zvonko says, good programming would be to check that the form exists ...
such as:

<cfif IsDefined("form.countryURL")>
    <cfset form_countryURL=form.countryURL>
<cfelseif IsDefined("url.countryURL")>
    <cfset form_countryURL=url.countryURL>
<cfelse>
    <cfset form_countryURL='US'>
</cfif>
This way, if the page is called in any way that is unexpected by you, there is a default value.

Second, you are getting confused with your "absolute" paths ...
    *    the "Absolute" path required by Coldfusion (CFINCLUDE, CFFILE, CFIMAGE, etc), is the absolute file as found on the server harddrive. (eg: c:\inetpub\wwwroot\educationconsulatant\others\menu.swf")
    *    the "Absolute" path required by the Browser (IMG,LINK,SCRIPT,etc)to render the page, is relative to the root folder (eg: \educationconsulatant\others\menu.swf)
    *    the ONLY time when the Absolute path "c:\inetpub\wwwroot\..." will work in a browser, is on the machine on which the webserver, and coldfusion reside ...

In you example, does #request.absolutpath# end in "\" ?
<cfset request.absolutepath='c:\inetpub\wwwroot\educationconsultant\'>
<cfset request.absoluteDIR='c:\inetpub\wwwroot\educationconsultant\'>
<cfset request.absoluteURL='/educationconsultant/'>
 
<cfsavecontent variable="topbar">
<cfoutput>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<cfinclude template="#request.absoluteDIR#meta.cfm">
<link rel="stylesheet" type="text/css" href="#request.absoluteURL#style.cfm" media="screen" />
<script language="javascript" type="text/javascript" src="#request.absoluteURL#other/flashobject.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript" src="#request.absoluteURL#stmenu.js"></script>
<script language="javascript" type="text/javascript" src="#request.absoluteURL#other/scroller.js"></script>
<script language="javascript" type="text/javascript" src="#request.absoluteURL#other/jsfile.js"></script>
<cfajaximport tags="cfform">
</head>
<Body leftmargin=0 topmargin=0 marginheight="0" marginwidth="0">
<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%">
  <tr>
  
  <td width="50%" background="#request.absoluteURL#images/bg.gif"><img src="#request.absoluteURL#images/px1.gif" width="1" height="1" alt="" border="0"></td>
  <td valign="bottom" background="#request.absoluteURL#images/bg_left.gif"><img src="#request.absoluteURL#images/bg_left.gif" alt="" width="17" height="16" border="0"></td>
  <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><img src="#request.absoluteURL#images/main01.jpg" width="620" align="left" height="123"></td>
              <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="300" height="46" background="#request.absoluteURL#images/fon01.gif"><a href="index.cfm"><img src="#request.absoluteURL#images/but001.gif" width="67" height="46" border="0"></a><img src="#request.absoluteURL#images/separator.gif" width="2" height="46"><a href="contact.cfm"><img src="#request.absoluteURL#images/but002.gif" alt="Advanced Search" width="90" height="46" border="0"></a><img src="#request.absoluteURL#images/separator.gif" width="2" height="46"><a href="advsearch.cfm"><img src="#request.absoluteURL#images/but003.gif" alt="Contact Us" width="80" height="46" border="0"></a></td>
                  </tr>
                  <tr>
                    <td height="77" background="#request.absoluteURL#images/fon02.gif"><table width="235" border="0" align="center" cellpadding="5" cellspacing="0" background="">
                        <tr>
                          <th width="45"><font color="##FFFFFF"> SEARCH</font></th>
                          <td width="139"><input type="Text" name="Input" class="textfield_effect" style="text-align:right;"></td>
                          <td width="21"><input type="submit" value="" class="searchButton" name="search"></td>
                        </tr>
                      </table></td>
                  </tr>
                </table></td>
            </tr>
          </table></td>
      </tr>
    </table>
    <table border="0" cellpadding="0" cellspacing="0" width="100%" background="">
      <tr>
        <td colspan="3"><img src="#request.absoluteURL#images/px1.gif" width="1" height="1" alt="" border="0"></td>
      </tr>
      <tr>
        <td bgcolor="##CECECE" colspan="3"><img src="#request.absoluteURL#images/px1.gif" width="1" height="1" alt="" border="0"></td>
      </tr>
      <tr>
        <td width="276" align="center"><div id="colorarrow_id" ></div>
          <script type="text/javascript">
var fo = new FlashObject("#request.absoluteURL#other/menu.swf","colorarrow","140","180","6","##000000");
    fo.addParam("menu","true");
    fo.addParam("quality","best");
    fo.addParam("scale","noscale");
    fo.addParam("salign","LT");
    fo.addParam("wmode", "transparent");
    fo.write("colorarrow_id");
</script></td>
        <td valign="bottom"><img src="#request.absoluteURL#images/e01.gif" alt="" width="2" height="226" border="0"></td>
        <td><table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td colspan="2">&nbsp;</td>
            </tr>
            <tr>
              <td><a href=""><img src="#request.absoluteURL#images/b01.gif" width="243" height="40" alt="" border="0"></a></td>
              <td rowspan="5"><img src="#request.absoluteURL#images/top03.gif" width="259" height="200" alt="" border="0"></td>
            </tr>
            <tr>
              <td><a href=""><img src="#request.absoluteURL#images/b02.gif" width="243" height="40" alt="" border="0"></a></td>
            </tr>
            <tr>
              <td><a href=""><img src="#request.absoluteURL#images/b03.gif" width="243" height="40" alt="" border="0"></a></td>
            </tr>
            <tr>
              <td><a href=""><img src="#request.absoluteURL#images/b04.gif" width="243" height="40" alt="" border="0"></a></td>
            </tr>
            <tr>
              <td><a href=""><img src="#request.absoluteURL#images/b05.gif" width="243" height="40" alt="" border="0"></a></td>
            </tr>
            <tr>
              <td colspan="2" align="right" class="string"><strong>#DateFormat(now(),'dddd, mmmm, dd yyyy')#</strong></td>
            </tr>
          </table></td>
      </tr>
    </table>
  <div align="center" class="dodo"><img src="#request.absoluteURL#images/px1.gif" width="1" height="1" alt="" border="0"></div><br>
  <table width="100%">
    <tr>
      <td><cfinclude template="#request.absoluteDIR#menu.cfm"></td>
    </tr>
  </table>
  <table border="0" cellpadding="2" align="center" cellspacing="2" width="100%">
    <tr valign="top">
    
    <td width="206" align="left" valign="top"><cfinclude template="#request.absoluteDIR#quick.cfm"><a href="javascript:void(0);" onClick="WinOpen('tellfriend.cfm','500','500');" title="Tell Your Friends"><img title="Tell Your Friends" src="#request.absoluteURL#images/tell-a-friend.gif" alt="Tell Your Friends" border="0"></a><a href="forums.cfm" target="_blank" title="Our Discussion Board"><img title="Our Discussion Board" src="#request.absoluteURL#images/discussion.jpg" alt="Discussion Board" width="100" height="70" border="0"></a><br></td>
    <td>
    </cfoutput>
</cfsavecontent>
 
<cfsavecontent variable="bottombar">
</td>
    
    </tr>
    
  </table>
  <br>
  <cfinclude template="#request.absoluteDIR#footer.cfm">
</body>
</html>
</cfsavecontent>

Open in new window

0
Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 24020728
but still get the same error:
The filename, directory name, or volume label syntax is incorrect
i think i have something going wrong here
<cfinvoke component="#request.cfcPath#.tools" method="addnewdeal" argumentcollection="#form#"/>
      <cfset templatePage = 'makepages.cfm'>
      <cfinclude template="#templatePage#">
      <cffile action="write" file="#request.absolutePath##form.countryURL#.cfm" output="#topbar#">
      <cfset show = "Cool! Successfully Processed">


had put the default form as:
<cfparam name="form.countryurl" default="US"> on top to make sure null value does not go empty
0
 
LVL 2

Expert Comment

by:albrandwood
ID: 24020986
OK ... can you provide the values for:

request.cfcPath
request.absolutPath
form.countryURL.cfm

Also, if it's not too big, can you provide the code for addnewdeal ?

thx
0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 24021272
yeah ok no issues, i will provide u full detail here:
<cfset request.basePath = "http://localhost/educationconsultant/">
  <cfset request.absolutePath = "c:\inetpub\wwwroot\educationconsultant\">
<cfset request.cfcpath = cfc>

addnewdeal code:
<cfquery datasource="#request.dsn#" username="#request.user#" password="#request.pass#" name="myset">
    INSERT INTO dealingcountries(country,flagimage,status,countryurl) 
    VALUES (<cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(arguments.countrieslist)#">,
    <cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(arguments.inpoint)#">,
    <cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(arguments.enable)#">,
    <cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(arguments.countryURL)#">)
    </cfquery>


what i did is this:
<cfset form.countryURL = #form.countrieslist#>
      <cfinvoke component="#request.cfcPath#.tools" method="addnewdeal" argumentcollection="#form#"/>
      <!---<cfset templatePage = 'makepages.cfm'>
      <cfinclude template="#templatePage#">--->
      <cffile action="write" file="#request.absolutePath##form.countryURL#.cfm" output="Any">
      <cfset show = "Cool! Successfully Processed">


just diabled the
      <!---<cfset templatePage = 'makepages.cfm'>
      <cfinclude template="#templatePage#">--->


and it worked but it created the page and the content of the created page was: ANY because i have written something like this:
     <cffile action="write" file="#request.absolutePath##form.countryURL#.cfm" output="Any">
So what is actually going wrong here, i do not know
0
 
LVL 2

Accepted Solution

by:
albrandwood earned 500 total points
ID: 24021575
ok ... so check that the following are CF expects them ...

makePages.cfm is in the current folder (whatever that may be).
c:\inetpub\wwwroot\educationconsultant\meta.cfm
c:\inetpub\wwwroot\educationconsultant\menu.cfm
c:\inetpub\wwwroot\educationconsultant\quick.cfm
c:\inetpub\wwwroot\educationconsultant\footer.cfm

Then when you have done that, replace
<cfinclude template="#templatePage#">
with
<cftry>
    <cfinclude template="#templatePage#">
    <cfcatch type="missinginclude">
        <cfdump var="#cfcatch#">
    </cfcatch>
</cftry>

then change the cffile to:
<cffile action="write" file="#request.absolutPath##form.CountryURL#.cfm" output="#topbar#Some HTML Text Goes Here#bottombar#">
0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 24021969
Ok i played it with and get around something, i did made some changes like:
<cfset newway = #Replace(request.absoluteURL,'/','','All')#>
<cfdump var="#newway#">
<cfif IsDefined("#newway#")>
 <cfset request.cfcPath = "admin.cfc">
</cfif>
<cfinclude template="#request.absoluteURL#meta.cfm">


using request.absoluteURL in my included files.
  • First i removed all included files from the makepages.cfm template
  • then it worked.
  • then i changed the path of the included files as above
  • they did not worked.
  • i got error:Ensure that the name is correct and that the component or interface exists. Could not find the ColdFusion Component or Interface cfc.tools.
  • This was coming as it was getting the path from application.cfc file as request.cfcpath = cfc.tools
  • while i hardcoded it to admin.cfc.tools. it worked.
  • then i added the above code u see
  • <cfset newway = #Replace(request.absoluteURL,'/','','All')#>
    <cfdump var="#newway#">
    <cfif IsDefined("#newway#")>
     <cfset request.cfcPath = "admin.cfc">
    </cfif>
  • to get the required cfc for this page but it did not worked.
  • Something going wrong here
One more stuff, what i need to incclude a<cfoutput>#now()#</cfoutput> to be dynamic.

0
 
LVL 16

Author Closing Comment

by:Gurpreet Singh Randhawa
ID: 31564333
Thanks, Solved
0

Featured Post

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question