Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

<cfif> help

New Here ,
Jan 27, 2009 Jan 27, 2009
Hello

I'm new to CF and need some help with a form. I have three radio buttons and one is <cfinput type="radio" name="rsvp" value="Yes, my spouse/partner will also attend"> (Other two are just Yes and No values with same name="rsvp") and if you select this one there is a form feild to fill in your spouse/partner's name (<cfinput type="text" size="15" name="spousepartner">). I would like it so if that radio button is marked, then it is required that the user fills in the corresponding text feild, giving them an error if they do not. Also, when the form is submitted an email will go out containing the form information, and I would like there to be a line that displays the Spouse/partner's name ONLY if that option was checked and a name was supplied.

Example---

RSVP: #form.rsvp#
Spouse/Partner's Name: #form.spousepartner# (Assuming they did select that option, otherwise just have the RSVP line)

I have no knowledge of how to use the <cfif> tag and was wondering if anyone could help me out here. Let me know if this requires furthur clarification (or if I'm rambling and need to shut up).

Thank you
Jakob
TOPICS
Getting started
675
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 27, 2009 Jan 27, 2009
iamjake182 wrote:
>
> I have no knowledge of how to use the <cfif> tag and was wondering if anyone
> could help me out here. Let me know if this requires furthur clarification (or
> if I'm rambling and need to shut up).
>
> Thank you
> Jakob
>

There is no real mystery to the <cfif...> tag itself. It is just a
plain, vanilla boolean if|then|else operation.
I.E.
<cfif {some condition}>
<!-- then do this if condition is true-->
<cfelse> <!---optional --->
<!-- else do this if condition if false -->
</cfif>

Where you may not realize you are asking a more complex question is
*where* do you want to evaluate if that radio button is selected and how
the http standard handles form radio buttons when they are not selected.

First a side comment: Reading your description I think a check box might
be a better choice then a radio button. The problem with a single radio
button is that once they are selected in a form, they can not be
un-selected by clicking on them again. One has to click on another
radio control in the same group, which is not possible in a group of one.

But as the rest of this discussion applies equally to radio button or
check box controls that is just a but of user interface advice.

For the first problem, where do you want to evaluate the radio button
and|or check box? Some of what you mentioned is probably client side
processing and that would require the use of JavaScript. There are many
tutorials on how to use JavaScript to create dynamic, optional sections
of a form. Some of what you mentioned is clearly server side
processing. Here there is nothing special about a radio button or check
box control. To the ColdFusion server they are just form fields and are
accessed by their field name.

With one caveat. And that is how the HTTP standard handles unchecked
radio buttons and|or check boxes. And that is that the browser does not
send any form fields for these controls if they are not selected. So on
the server side processing you have to account for the fact that these
fields may or may not exist in the posted form data, if they where not
selected by the user.

The most commons ways to do this is either to provide default values for
the controls usually with a <cfparam ...> tag so that to will always
exist. Or to test for their existence during the processing of your
form data.

Ian
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 09, 2009 Feb 09, 2009
LATEST
do you have to use radio buttons? cause here is one i found works but then you will have to impliment the spouce field for entering their name

<SCRIPT LANGUAGE="JavaScript"><!--
function codename() {

if(document.formname.prim.checked)
{
document.formname.multi.disabled=true;
}

else
{
document.formname.multi.disabled=false;
}
}

//-->
function codename1() {

if(document.formname.multi.checked)
{
document.formname.prim.disabled=true;
}

else
{
document.formname.prim.disabled=false;
}
}
//-->
function codename2() {
if(document.formname.Etc.checked)
{

document.formname.Mtc.disabled=true;
document.formname.Tur.disabled=true;
document.formname.wegb.disabled=true;
document.formname.ost.disabled=true;
document.formname.other.disabled=true;
document.formname.Pmtc.disabled=true;
document.formname.Ctel.disabled=true;
document.formname.Cmtc.disabled=true;
document.formname.Cmtt.disabled=true;
document.formname.Supplemental.disabled=true;

}

else
{
document.formname.Mtc.disabled=false;
document.formname.Tur.disabled=false;
document.formname.wegb.disabled=false;
document.formname.ost.disabled=false;
document.formname.other.disabled=false;
document.formname.Pmtc.disabled=false;
document.formname.Ctel.disabled=false;
document.formname.Cmtc.disabled=false;
document.formname.Cmtt.disabled=false;
document.formname.Supplemental.disabled=false;
}
}

//-->
function codename3() {
if(document.formname.Mtc.checked)
{

document.formname.Etc.disabled=true;
document.formname.Tur.disabled=true;
document.formname.wegb.disabled=true;
document.formname.ost.disabled=true;
document.formname.other.disabled=true;
document.formname.Pmtc.disabled=true;
document.formname.Ctel.disabled=true;
document.formname.Cmtc.disabled=true;
document.formname.Cmtt.disabled=true;
document.formname.Supplemental.disabled=true;

}

else
{
document.formname.Etc.disabled=false;
document.formname.Tur.disabled=false;
document.formname.wegb.disabled=false;
document.formname.ost.disabled=false;
document.formname.other.disabled=false;
document.formname.Pmtc.disabled=false;
document.formname.Ctel.disabled=false;
document.formname.Cmtc.disabled=false;
document.formname.Cmtt.disabled=false;
document.formname.Supplemental.disabled=false;
}
}

//-->
</SCRIPT>

<cfform action="../test.cfm" method="" name="formname">



<table class="form" height="300" width="607"> <tr>
<td width="24"> </td>


<td colspan="3"> </td>
<td colspan="2"><strong>Type</strong></td>
<td width="303"> </td>
</tr>
<tr>
<td><cfinput name="prim" type="checkbox" onclick="codename()" value="1" /></td>
<td colspan="4">Primary</td>
<td width="20"><cfinput name="multi" type="checkbox" onclick="codename1()" value="1" /></td>
<td>Multiplier</td>
</tr>
<tr>
<td colspan="7"> </td>
</tr>
<tr>
<td> </td>
<td colspan="3"> </td>
<td colspan="2"><strong>SubPart</strong></td>
<td> </td>
</tr><!--- make sure that you create the function for all of them and call it the same name as the onclick --->
<tr>
<td><cfinput name="Etc" type="checkbox" onclick="codename2()" value="1" /></td>
<td colspan="4">B - E T C</td>
<td><cfinput name="Mtc" type="checkbox" onclick="codename3()" value="1" /></td>
<td>C - MTC</td>
</tr>
<tr>
<td><cfinput name="Tur" type="checkbox" onclick="codename4()" value="1" /></td>
<td colspan="4">D - Tur</td>
<td><cfinput name="wegb" type="checkbox" onclick="codename5()" value="1" /></td>
<td>E - WEPG</td>
</tr>
<tr>
<td><cfinput name="ost" type="checkbox" onclick="codename6()" value="1" /></td>
<td colspan="4">F - Ost</td>
<td><cfinput name="other" type="checkbox" onclick="codename7()" value="1" /></td>
<td>G - Other</td>
</tr>
<tr>

</tr>
<tr><td height="24" colspan="8"></a> <!--- need to make searches for all forms because of different attributes on every form --->
</tr></table><input type="submit" value="submit" />
</cfform>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources