Skip to main content
Participant
April 18, 2008
Question

CFIF using cfinput "value"

  • April 18, 2008
  • 7 replies
  • 544 views
Hello

I am creating a cfmformng radio buttons to select the number of people that will join a party, there are 4 radio buttons for the max number of 4 participants in the group. what i want to do is send the form to the response page differently based on the number of people chosen. I could use a cfif statement for this easily, i just don't know how to determine the number of people chosen for the cfif statement. Any help on this would be much appreciated.

Here are my radio buttons:
    This topic has been closed for replies.

    7 replies

    BKBK
    Community Expert
    Community Expert
    April 20, 2008
    -==cfSearching==- wrote:
    since the field is a radio button it only exists on the action page if something was checked.

    True, but not necessary here. The first radio element is checked by default.


    Inspiring
    April 20, 2008
    BKBK wrote:
    True, but not necessary here. The first radio element is checked by default.

    True enough, but having a default does not hurt here. That is my preference anyway.

    I would just do the obvious: extract the number from the value of the form field.
    <cfset numberOfPeople = Left(form.players, 1)>
    ..


    Yes, that would work. However, I agree with tclaremont's suggestion. Unless there is a good reason the values must be "1 Player", "2 Player", etcetera I would use simple numeric values instead.
    BKBK
    Community Expert
    Community Expert
    April 20, 2008
    RexusFirm wrote:
    I could use a cfif statement for this easily, i just don't know how to determine the number of people chosen for the cfif statement.

    I would just do the obvious: extract the number from the value of the form field.

    <cfset numberOfPeople = Left(form.players, 1)>
    <cfif numberOfPeople eq 1>
    <cfelseif numberOfPeople eq 2>
    ...
    etc.
    </cfif>

    or, perhaps

    <cfswitch expression="#left(form.players,1)#">
    <cfcase value="1">
    </cfcase>
    <cfcase value="2">
    </cfcase>
    <cfcase value="3">
    </cfcase>
    <cfcase value="4">
    </cfcase>
    </cfswitch>

    Inspiring
    April 20, 2008
    On my action page would I be able to do something like <cfset playerValue = #Form.Players#> and then start my <cfif> ?

    Yes. Though you probably do not need cfset. Just use the form field directly: #form.players# . However, since the field is a radio button it only exists on the action page if something was checked. You can use cfparam or IsDefined to ensure the form field exists before using it in code.

    <cfparam name="form.players" default="1">
    <cfif form.players eq 1>
    ... etcetera
    </cfif>
    Inspiring
    April 18, 2008
    RexusFirm wrote:
    > On my action page would I be able to do something like <cfset playerValue = #Form.Players#> and then start my <cfif> ?


    You sure could. You could also just use form.Players in your <cfif...>
    logic. No need to assign it to another variable if you are not going to
    do anything else with that variable.
    RexusFirmAuthor
    Participant
    April 18, 2008
    On my action page would I be able to do something like <cfset playerValue = #Form.Players#> and then start my <cfif> ?
    Inspiring
    April 18, 2008
    RexusFirm wrote:
    > What i want to do is send the form to the response
    > page differently based on the number of people chosen.

    This is an unclear statement. What do you want to happen where.

    The easiest scenario is that your action page does stuff based on the
    value of form.players.

    I.E.

    <cfswitch expression="#form.players#">
    <cfcase value="1 Player">
    <!--- Do One Player Stuff --->
    </cfcase>
    <cfcase value="2 Players">
    <!--- Do Two Player Stuff --->
    </cfcase>
    <cfcase value="3 Players">
    <!--- Do Three Player Stuff --->
    </cfcase>
    <cfcase value="4 Players">
    <!--- Do Four Player Stuff --->
    </cfcase>
    <cfdefaultCase>
    <!--- How did I get here? Form.player did not equal any of the
    four expected values --->
    </cfdefaultCase>
    </cfswitch>

    The same thing could be done with <cfif> with or without <cfelseif> blocks.
    tclaremont
    Inspiring
    April 18, 2008
    On your form page, change each input value on your form from "1 Player" to "1", etc, unless you have a good reason for the value to be '1 Player' rather than '1'

    Then, in the action page, refer to #Form.Players#.