0

I'm working on a Coldfusion project and I seem to be stuck. I am a newbie so I hope I don't get too much slack. The purpose of my project is to create a password list by using nested loops. I am to design a template that combines all words in the list "cold, fusion, dynamic" with all words on the list "bert, ernie, oscar" to produce a bulleted list of vaild passwords. This template should process two URL prarameters named List1 and List2. I must use two list loops nested within each other to produce all possible combinations of words. (For example "coldbert", "coldernie", "coldoscar", "fusionbert" and so on..)

This is what I have so far:

<cfinclude template="header.cfm">
<body>

<h2>Loop List</h2>


<cfhttp url="looplist.cfm?List1=cold,fusion,dynamic&List2=bert,ernie,oscar" method="get">

<CFLOOP LIST="#URL.List1#"
INDEX="List1">
<UL><CFOUTPUT>#List1#</CFOUTPUT></UL><br>
</CFLOOP>


<cfinclude template="footer.cfm">

I want to ensure that I'm going in the right direction here. Thanks guys for any assistance.

2
  • I would start with figuring out the loop code first. Then figure out how to use it as a template. However, one issue with the above is the URL.list1 variable will only exist on the page you are calling, ie loopList.cfm. Commented Mar 5, 2017 at 22:32
  • ... also, to avoid confusion do not use List1 for both the index and variable names. Use two different names. Commented Mar 5, 2017 at 22:56

1 Answer 1

3

Unless you're calling a page that doesn't exist on your site, I do not see a need to do a http call. You could just create a function in the template (although I'd prefer it to be in a separate cfc) and call that to get your password combos. Something like ...

<cffunction name="getPasswordCombos" returntype="string">
    <cfargument name="list1" type="string" required="true" />
    <cfargument name="list2" type="string" required="true" />

    <cfset var passwordCombos = "" />
    <cfset var i = "" />
    <cfset var j = "" />

    <!--- your combo generation logic might look something like --->
    <cfloop list="#arguments.list1#" index="i">
        <cfloop list="#arguments.list2#" index="j">
            .....
            <!--- set passwordCombos logic here --->
            .....
        </cfloop>           
    </cfloop>

    <cfreturn passwordCombos />
</cffunction>

Then,

<cfset passwordCombos = getPasswordCombos("cold,fusion,dynamic", "bert,ernie,oscar") />

Then loop over the "passwordCombos"

<ul>
    <cfloop list="#passwordCombos#" index="i">
        <li>#i#</li>
    </cfloop>
</ul>

Also, if you HAVE to user CFHTTP, use cfhttpparam to pass in arguments. It's much cleaner.

<cfhttp result="result" url="looplist.cfm" method="GET">
    <cfhttpparam name="list1" type="url" value="cold,fusion,dynamic">
    <cfhttpparam name="list2" type="url" value="bert,ernie,oscar">
</cfhttp>
Sign up to request clarification or add additional context in comments.

1 Comment

Agreed. Unless the homework assignment requires using cfhttp, don't. There are simpler options.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.