EasyCFM.COM ColdFusion Forums / PHP to CFML / simple (?) Function conversion

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: simple (?) Function conversion

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

billybrag
09-12-2006 @ 6:43 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 163
Joined: Feb 2006

hi all i have done this captcha (text only) in php and wondered if anyone could help me turn it into coldfusion.

It could be of use to a few people
**************php*******************************
        function captcha() {
          $numbers = array("zero", "one", "two", "three",  "four", "five",  "six", "seven", "eight", "nine");
          $rand = array_rand($numbers,2);
          $result=$rand[0]+$rand[1];
          $question = "<b>".$numbers[$rand[0]]."</b> plus <b>".$numbers[$rand[1]]."</b>";
          $out .= '<label for="captcha">Please enter the result into the box below:(Answer in numbers only)<br /> '.$question.' equals</label> <input type="text" name="captcha"id="captcha">';
       $out .= '<INPUT TYPE=hidden NAME=val1 VALUE='.$numbers[$rand[0]].'>';
       $out .= '<INPUT TYPE=hidden NAME=val2 VALUE='.$numbers[$rand[1]].'>';
       $out .= '<INPUT TYPE=hidden NAME=result VALUE='.$result.'>';
          return $out;
      }
**********************end php***********************

Thanks
Mike Sharp

www.organiclinker.com

mquack
09-12-2006 @ 1:25 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 1544
Joined: Jan 2005

I don't know the first thing about PHP so I can't actually translate your script for you, but from my glance thru it I would say that you're looking for arrayNew(1) and randRange() in ColdFusion.  (I am assuming that you know how to write a function (a.k.a. UDF) in CF.)

http://www.rachelqueensg.com

CJ
09-12-2006 @ 7:00 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4262
Joined: Oct 2002

<cfscript>
     function captcha() {
          var numbers     = listToArray("zero, one, two, three, four, five, six, seven, eight, nine");
          
          var rand1     = randRange(1, arrayLen(numbers));
          var rand2     = randRange(1, arrayLen(numbers));
          var result     = rand1 + rand2 - 2;     // subtract 2 since CF arrays start at 1 as opposed to 0
          var question= "<b>" & numbers[rand1] & "</b> plus <b>" & numbers[rand2] & "</b>";
          var out          = "";
          
          out               = "<label for='captcha'>Please enter the result into the box below: (Answer in numbers only)<br />" & question & " equals</label>";
          out               = out & "<input type='hidden' name='val1' value='" & rand1 & "'>";
          out               = out & "<input type='hidden' name='val2' value='" & rand2 & "'>";
          out               = out & "<input type='hidden' name='result' value='" & result & "'>";
          
          return output;
     }
</cfscript>

<cfoutput>#captcha()#</cfoutput>


-CJ-
@ #coldfusion/DALNet
http://charlie.griefer.com

Teachers open the door. You enter by yourself.
—Chinese Proverb


Website Designed and Developed by Pablo Varando.