Skip to main content
Fabiano Magno Pechibella
Inspiring
April 1, 2013
Question

Loop PHP to CF, how make?

  • April 1, 2013
  • 1 reply
  • 689 views

Guys,

I have the script PHP below.

How I write this script in ColdFusion, sorry for the dummie's ask

<?php

          if(isset($_POST[“color”])) {          

             for($i = 0; $i < count($_POST[“color”]); $i++) {

                  echo “The color “.$_POST[“color”][$i].” was selected!<br />”;

              }

          } else {

              echo “blablablablablablablabla”

          }

?>

[ ]'s

    This topic has been closed for replies.

    1 reply

    Inspiring
    April 1, 2013

    I assume on the form, colour is a series of checkboxes.

    if (StructKeyExists(form, "color") {

    for (i = 1; i lte ListLen(form.color); i++)

    writeoutput("The color #ListGetAt(form.color, i)# was selected<br>") ;

    }

    else {

    }

    Fabiano Magno Pechibella
    Inspiring
    April 2, 2013

    Hi Dan,

    Tks for your answer, my doubt is.  Where putting this code, inside a tag <cfscript> or a <cfif>.

    You Could, show me a example?

    Thanks one more time.

    [ ]'s

    Fabiano Magno Pechibella

    Inspiring
    April 2, 2013

    The code I wrote would go inside a set of <cfscript> tags.  The tag based version would be:

    <cfif StructKeyExists(form, "color")>

    <cfoutput>

    <cfloop list = "#form.color#" index = "ThisColor">

    The color #ThisColor# was selected.<br>

    </cfloop>

    <cfoutput>

    <cfelse>

    code for no boxes checked.

    </cfif>