How to make radio buttons in a form "not required"

Discussion in 'Programming' started by lespaul00, Jan 13, 2008.

  1. #1
    Here is part of my form that asks for a user's gender. If I leave it blank when testing it,

    					  <cfinput 
    					type="radio" name="USER_GENDER"
    					value="male"/>
    					  Male
    					  <cfinput 
    					type="radio" name="USER_GENDER"
    					value="female"/>
    					  Female
    Code (markup):
    The only way I was able to workaround this, was to place a third option that I marked as checked:

    					  <cfinput 
    					type="radio" name="USER_GENDER"
    					value="male"/>
    					  Male
    					  <cfinput 
    					type="radio" name="USER_GENDER"
    					value="female"/>
    					  Female
    					  <cfinput 
    					type="radio" name="USER_GENDER"
    					value="It's a secret!" 
    					checked="yes"/>
    					  It's a secret!
    Code (markup):
    How else can I allow a user to leave this field blank? I tried using cfset USER_GENDER="" before the input fields, but this didn't correct the issue.
     
    lespaul00, Jan 13, 2008 IP
  2. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What happens?
     
    cfStarlight, Jan 14, 2008 IP
  3. LaughingHyena

    LaughingHyena Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I guess, when you submit the form, without checking any radio button.. it would complain that

    #FORM.USER_GENDER# is not defined

    ______
    If that is the problem, add this to where you are reading that field in the second cfm page:

    <cfset userGender ="">
    <cfif isDefined("FORM.USER_GENDER")>
       <cfset userGender  = FORM.USER_GENDER>
    </cfif>
    
    Code (markup):
     
    LaughingHyena, Jan 15, 2008 IP
  4. dshuck

    dshuck Peon

    Messages:
    92
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Typically this is what the <cfparam/> tag is for:
    
    <cfparam name="form.user_gender" default="" />
    
    Code (markup):
    If no value is passed form.user_gender will be blank. Otherwise it will be overwritten.
     
    dshuck, Feb 1, 2008 IP