Avatar of Shawn
ShawnFlag for Canada

asked on 

Element is undefined in FORM

hi,

I am setting up a form that keeps throwing the error "Element is undefined in FORM " once I click on send. Not sure why this is since I set up <cfparam name="form.Title" default=""> at the beginning of the form.

I should mention that I have 2 pages 1. dsp_ to display and an act_ to send us an email if mandatory fields are filled...otherwise it resubmits to itself.

I copied this from another part or our site which works fine.

dsp_translation_test_english.cfm
contains
 
 
 
<cfparam name="form.Title" default="">
<cfparam name="Form.Tr" default="">
<cfparam name="form.Testtext" default="">
<cfparam name="form.Source" default="">
<cfparam name="form.Target" default="">
<cfparam name="form.SourceCurrencyRate" default="">
<cfparam name="form.SourceCurrency" default="">
<cfparam name="form.TranslatorType" default="">
<cfparam name="form.LastName" default="">
<cfparam name="form.FirstName" default="">
<cfparam name="form.email" default="">
<cfparam name="form.company" default="">
<cfparam name="form.Country" default="">
<cfparam name="form.Telephone" default="">
<cfparam name="form.TranslatorStatus" default="">
<cfparam name="form.TranslatorsDiploma" default="">
<cfparam name="form.YearTranslationDiplomaObtained" default="">
<cfparam name="form.YearsTranslating" default="">
<cfparam name="form.CatTool" default="">
<cfparam name="form.CatToolOther" default="">
<cfparam name="form.otherinfo" default="">
 
 
<cfif isdefined('form.fullmessage')> 
<p><font color="#FF0000"><strong><cfoutput>#fullmessage#</cfoutput></strong></font></p>
</cfif>
 
 
<p>&nbsp;</p>
<p>Welcome to Araxi's translation test area. </p>
            <Cfoutput> 
<FORM action=index.cfm?action=home.ttest-act method=post enctype="multipart/form-data" name="form">
 
    <p> 
      <input type="Hidden" name="FORMTYPE" value="TranslationTest">
      <cfinclude template="cfformprotect/cffp.cfm">
    </P>
      
    <table valign="top" class="submenu"width="90%" border="0" cellspacing="0" cellpadding="5">
      <tr> 
        <td height="20" colspan="4" bordercolor="98012E" bgcolor="98012E" class="menu">
<div align="center"><font color="##FFFFFF">Translation 
            Test </font></div></td>
      </tr>
      <tr> 
        <td colspan="2" valign="top"><p>Job Reference*</p>
          </td>
        <td colspan="2" valign="top"><p> 
            
			<cfif FORM.Tr NEQ "">
              #Tr# <span class="smallbodytext">(to change the reference</span> 
              <a href="<cfoutput>#script_name#?action=home.ttest</cfoutput>" >click 
              here</a><span class="smallbodytext">)</span> 
              <cfelse>
              <INPUT name="Tr" class=formcell id="Tr"  value=''size=10 maxLength=5>
            </cfif>
          </p>
          </td>
      </tr>
      <tr>
        <td colspan="2" valign="top">Title</td>
        <td colspan="2" valign="top">Architect comments for client</td>
      </tr>
      <tr> 
        <td colspan="2" valign="top"> <p>Job description and instructions</p>
          <p>&nbsp;</p>
          <p>&nbsp;</p></td>
        <td colspan="2" valign="top">goes here</td>
      </tr>
      <tr> 
        <td colspan="2" valign="top"><p>Test text</p></td>
        <td colspan="2" valign="top" bordercolor="98012E"> <table width="100%" border="1" valign="top" cellpadding="0" cellspacing="0" bordercolor="98012E">
            <tr> 
              <td>this is the test text</td>
            </tr>
          </table>
          <p>&nbsp;</p>
          </td>
      </tr>
      <tr> 
        <td colspan="2"><strong>Your Translation</strong><br>
          <span class="smallbodytext">please be sure you have proofed and done 
          a spell check. (stangely this is often overlooked for &quot;quick&quot; 
          tests)</span></td>
        <td colspan="2"><TEXTAREA class=formcell name=Testtext rows=5 cols=50></TEXTAREA></td>
      </tr>
      <tr> 
        <td colspan="2">&nbsp;</td>
        <td colspan="2">&nbsp;</td>
      </tr>
      <tr> 
        <td colspan="2"><p>Source language 
            <select name="Source" size="1" class=formcell id="Source" >
              <cfif isdefined ("form.Source")>
                <cfloop query="getSLang">
                  <option value='#getSLang.Slang#' <cfif getSLang.Slang eq form.Source>selected="true"</cfif>>#getSLang.Slang#</option>
                </cfloop>
                <cfelse>
                <option>- select -</option>
                <cfloop query="getSLang">
                  <option value='#getSLang.Slang#'>#getSLang.Slang#</option>
                </cfloop>
              </cfif>
            </select>
          </p></td>
        <td colspan="2">Target language 
          <select name="Target" size="1" class=formcell id="Target" >
            <cfif isdefined ("form.Target")>
              <cfloop query="getTLang">
                <option value='#getTLang.Tlang#' <cfif getTLang.Tlang eq form.Target>selected="true"</cfif>>#getTLang.Tlang#</option>
              </cfloop>
              <cfelse>
              <option>- select -</option>
              <cfloop query="getTLang">
                <option value='#getTLang.Tlang#'>#getTLang.Tlang#</option>
              </cfloop>
            </cfif>
          </select> </td>
      </tr>
      <tr> 
        <td colspan="2">Your source rate for the job*</td>
        <td colspan="2"><INPUT name=SourceCurrencyRate class=formcell id=SourceCurrencyRate  size=5 
                        maxLength=5> <select name="SourceCurrency" size="1" class=formcell id="SourceCurrency" >
            <option value="USD">USD</option>
            <option value="CAD">CAD</option>
            <option value="EUR">EUR</option>
            <option value="GBP">GBP</option>
          </select></td>
      </tr>
      <tr> 
        <td height="20" bgcolor="98012E" class="menu" colspan="4"><div align="center"><font color="##FFFFFF">About 
            You </font></div></td>
      </tr>
      <tr bgcolor="##FFFFCC" class="submenuparentlink"> 
        <td valign="bottom">
		<input type="radio" name="Title" value="Mrs" id="Title" >
          Mrs 
        <input type="radio" name="Title" value="Ms" id="Title">
          Ms 
        <input type="radio" name="Title" value="M" id="Title">
          Mr </td>
        <td>&nbsp;</td>
        <td><p> 
            <input type="radio" name="TranslatorType" value="Independant" id="TranslatorType" >
            Independant <br>
            <input type="radio" name="TranslatorType" value="Group of translators" id="TranslatorType" >
            Group of translators <br>
            <input type="radio" name="TranslatorType" value="Translation Agency" id="TranslatorType" >
            Translation Agency </p></td>
        <td><p><br>
            <br>
          </p></td>
      </tr>
      <tr bgcolor="##FFFFCC"> 
        <td>Name*</td>
        <td> <INPUT name=LastName class=formcell id=LastName3  size=15 
                        maxLength=30></td>
        <td>Company</td>
        <td> <INPUT class=formcell id=company maxLength=30 
                        size=15 name=company></td>
      </tr>
      <tr bgcolor="##FFFFCC"> 
        <TD align="left"> <DIV align=left>First name</DIV></TD>
        <TD align="left" > <INPUT class=formcell id=FirstName 
                        maxLength=30 size=15 name=FirstName></TD>
        <TD align="left">Country*</TD>
        <TD align="left"> <DIV align=left> 
            <INPUT class=formcell id=Country 
                        maxLength=30 size=15 name=Country>
          </DIV></TD>
      </tr>
      <tr bgcolor="##FFFFCC"> 
        <TD align="left"> <DIV align=left> 
            <p>email*</p>
          </DIV></TD>
        <TD align="left" > <INPUT name=email class=formcell id=email  size=15 
                        maxLength=30> </TD>
        <TD align="left">Phone</TD>
        <TD align="left"> <DIV align=left> 
            <INPUT class=formcell maxLength=30 
                        size=15 name=Telephone>
          </DIV></TD>
      </tr>
      <tr bgcolor="##FFFFCC"> 
        <TD colspan="2" align="left">Do you have a translator's diploma? </TD>
        <TD colspan="2" align="left"><input type="radio" name="TranslatorsDiploma" value="true" id="TranslatorsDiploma" >
          yes 
          <input type="radio" name="TranslatorsDiploma" value="false" id="TranslatorsDiploma" >
          no. If yes, year obtained 
          <INPUT name=YearTranslationDiplomaObtained class=formcell id=YearTranslationDiplomaObtained4  size=4 
                        maxLength=4></TD>
      </tr>
      <tr bgcolor="##FFFFCC"> 
        <TD colspan="2" align="left">You translate </TD>
        <TD colspan="2" align="left"><input type="radio" name="TranslatorStatus" value="Full Time" id="TranslatorStatus" >
          full time 
          <input type="radio" name="TranslatorStatus" value="Part Time" id="TranslatorStatus" >
          part time </TD>
      </tr>
      <tr bgcolor="##FFFFCC"> 
        <TD colspan="2" align="left">Number of years translating</TD>
        <TD align="left"> <INPUT name=YearsTranslating class=formcell id=YearsTranslating3  size=2 
                        maxLength=2></TD>
        <TD align="left">&nbsp;</TD>
      </tr>
      <tr bgcolor="##FFFFCC"> 
        <TD align="left">CAT tools used: </TD>
        <TD align="left" ><br> </TD>
        <TD align="left" valign="top"> <input name="CatTool" type="checkbox" id="CatTool4" value="Deja Vu">
          D&eacute;j&agrave; Vu<br> <input name="CatTool" type="checkbox" id="CatTool4" value="Trados">
          Trados<br>
          Other 
          <INPUT name=CatToolOther class=formcell id=CatToolOther  size=15 
                        maxLength=30></TD>
        <TD align="left" valign="top"> <input name="CatTool2" type="checkbox" id="CatTool5" value="Wordfast">
          Wordfast<br> <input name="CatTool2" type="checkbox" id="CatTool5" value="OmegaT">
          OmegaT</TD>
      </tr>
      <tr bgcolor="##FFFFCC"> 
        <TD align="left">Your R&eacute;sum&eacute; or Profile</TD>
        <TD align="left" >&nbsp;</TD>
        <TD colspan="2" align="left"><input name="FILE" type="file" class=formcell id="FILE3"></TD>
      </tr>
      <tr bgcolor="##FFFFCC"> 
        <TD colspan="2" align="left">Other information you wish to give us<br> 
          <span class="smallbodytext"><font class="smalltext">(if you specialise 
          in any areas please specify)</font></span></TD>
        <TD colspan="2" align="left"><TEXTAREA class=formcell name=otherinfo rows=5 cols=50></TEXTAREA></TD>
      </tr>
      <tr bgcolor="##FFFFCC"> 
        <td colspan="4"> <table width="100%" cellspacing="0" cellpadding="0">
            <tr> 
              <td class="heading_RED"><p>*mandatory fields</p></td>
              <td align="right"> <INPUT class=button type=submit value=Send name=save> 
              </td>
            </tr>
          </table></td>
      </tr>
    </table>
	
    <p>&nbsp;</p>
    <p>&nbsp; </p>
    
      
    <P align=left class="bodytext">Please</P>
    </TD></TR><TR><TD class=bodytext vAlign="top" >&nbsp;</TD></TR></TABLE>
 
    </FORM>
	</CFOUTPUT> 
 
act_translation_test_english.cfm
contains
 
 
<cfif isdefined('form.save')>
 
	<cfset continue = true>
   <cfif FORM.Tr EQ "">
    <cfset form.msg1 = " The TestReference field is mandatory.<br>">
    <cfset continue = false>
	<cfelse>
	<cfset form.msg1 = "">
  </cfif>
  
  <cfif not REFindNocase("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.(([a-z]{2,3})|(aero|coop|info|museum|name))$", FORM.email)>
     <cfset form.msg2 = " A valid E-MAIL address is mandatory.<br>">
    <cfset continue = false>
	<cfelse>
	<cfset form.msg2 = "">
  </cfif>
  
    <cfif FORM.LastName EQ "">
    <cfset form.msg3 = " Your Name is mandatory.<br>">
    <cfset continue = false>
	<cfelse>
	<cfset form.msg3 = "">
  	</cfif>
	
   <cfif FORM.Country EQ "">
    <cfset form.msg4 = " Your Country is mandatory.<br>">
    <cfset continue = false>
	<cfelse>
	<cfset form.msg4 = "">
	</cfif>
	
   <cfif FORM.SourceCurrencyRate EQ "">
    <cfset form.msg5 = " Your Rate is mandatory.<br>">
    <cfset continue = false>
	<cfelse>
	<cfset form.msg5 = "">
  	</cfif>
	<cfelse>
	<cfset form.msg5 = "">
	</cfif>
	
  
  <cfset form.fullmessage = form.msg1 & form.msg2 & form.msg3 & form.msg4 & form.msg5>
    
   <cfif continue EQ false>      
 
<cfset Title = FORM.Title>
<cfset Tr = FORM.Tr>
<cfset Testtext = FORM.Testtext>
<cfset Source = FORM.Source>
<cfset Target = FORM.Target>  
<cfset SourceCurrencyRate = FORM.SourceCurrencyRate>
<cfset SourceCurrency = FORM.SourceCurrency>
<cfset TranslatorType = FORM.TranslatorType>
<cfset LastName = FORM.LastName>  
<cfset FirstName = FORM.FirstName>
<cfset email = FORM.email>
<cfset company = FORM.company>
<cfset Country = FORM.Country>
<cfset Telephone = FORM.Telephone>  
<cfset TranslatorStatus = FORM.TranslatorStatus>
<cfset TranslatorsDiploma = FORM.TranslatorsDiploma>
<cfset YearTranslationDiplomaObtained = FORM.YearTranslationDiplomaObtained>
<cfset YearsTranslating = FORM.YearsTranslating>  
<cfset CatTool = FORM.CatTool>
<cfset CatToolOther = FORM.CatToolOther>
<cfset otherinfo = FORM.otherinfo>  
 
	  
<cfinclude template="dsp_translation_test_#request.language#.cfm">
<cfelse>
 
<cfset Cffp = CreateObject("component","cfformprotect.cffpVerify").init() />
<!--- now we can test the form submission --->
	   <cfdump var=#cffp.testSubmission(form)# />
	   results here
	   <cfdump var=#form#>
 
<cfif Cffp.testSubmission(form)>
       <!--- The submission has passed the form test.  Place processing here --->
 
 
 <!--- email to us giving name of person referring and contacts --->
<cfmail to="webform@araxi.fr" from="website@araxi.fr" subject="translation test. Ref.: #form.TestReference#" type="HTML">
<p>Title: #form.Title#</p> 
<p>TestReference: #form.TestReference#</p>
<p>Testtext: #form.Testtext#</p>
<p>Source: #form.Source#</p>
<p>Target: #form.Target#</p>
<p>SourceCurrencyRate: #form.SourceCurrencyRate#</p>
<p>SourceCurrency: #form.SourceCurrency#</p>
<p>TranslatorType: #form.TranslatorType#</p> 
<p>LastName: #form.LastName#</p> 
<p>FirstName: #form.FirstName#</p> 
<p>email: #form.email#</p> 
<p>company: #form.company#</p> 
<p>Country: #form.Country#</p> 
<p>Telephone: #form.Telephone#</p> 
<p>TranslatorStatus: #form.TranslatorStatus#</p> 
<p>TranslatorsDiploma: #form.TranslatorsDiploma#</p> 
<p>YearTranslationDiplomaObtained: #form.YearTranslationDiplomaObtained#</p> 
<p>YearsTranslating: #form.YearsTranslating#</p> 
<p>CatTool: #form.CatTool#</p> 
<p>CatToolOther: #form.CatToolOther#</p> 
<p>otherinfo: #form.otherinfo#</p> 
 
 
<br>
</cfmail>

Open in new window

Web Servers

Avatar of undefined
Last Comment
Shawn
Avatar of _agx_
_agx_
Flag of United States of America image

> since I set up <cfparam name="form.Title" default=""> at the beginning of the form

   Yes, but that is on the "dsp_translation_test_english.cfm" page.  From what I can see there are
   no cfparam's on the action page   So "form.title" would be undefined if none of the radio buttons
   are checked.


> <FORM action=index.cfm?action=home.ttest-act method=post en

   Are you posting the form data directly to the action page ("act_translation_test_english.cfm")?
Avatar of Shawn
Shawn
Flag of Canada image

ASKER

>In the other form that works on the site it is done this way as well. I think this should be ok.

>Are you posting the form data directly to the action page ("act_translation_test_english.cfm")?
yes
Avatar of _agx_
_agx_
Flag of United States of America image

You have to add the cfparam's on the action page as well.  

Checkboxes and radio buttons do not exist unless they're checked.  None of the "Title" buttons are checked by default. So if the user submits the form that way, "form.Title" will be undefined.  So you have to set a default on the action page to prevent that error (or use IsDefined before accessing it).
Avatar of _agx_
_agx_
Flag of United States of America image

> >Are you posting the form data directly to the action page ("act_translation_test_english.cfm")?
> yes

I ask because that is not what your sample code says.  The action = index.cfm?action=home.ttest-act .
Avatar of Shawn
Shawn
Flag of Canada image

ASKER

oh, I have another page that sets these...

<cfelseif REQaction is "ttest">
<cfinclude template="dsp_translation_test_#request.language#.cfm">

<cfelseif REQaction is "ttest-act">
<cfinclude template="act_translation_test_#request.language#.cfm">
Avatar of _agx_
_agx_
Flag of United States of America image

Oh, okay.   That should work since you are using <cfinclude...>'s.

But you still have to use cfparam for the checkboxes and radio buttons.  Like I said, they do not exist on the action page unless they're checked.  So if nothing is checked .. and you don't set a default ... you get the "Element undefined..." error.   Make sense?
Avatar of Shawn
Shawn
Flag of Canada image

ASKER

but I do set it in the act_ page when in the line
<cfset Title = FORM.Title>

Avatar of Shawn
Shawn
Flag of Canada image

ASKER

here are 2 set of files. One set you have the dsp and act for this example translation_test.
The other is a very similar one called sponsor which works. If you look at the example of title it is pretty much the same.
4files.zip
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Shawn
Shawn
Flag of Canada image

ASKER

ok, I see your logic.

Could you have a quick look at the other files. I'm really curious to know why it worked in that case.
Avatar of trailblazzyr55
trailblazzyr55

This may be a "given", however perhaps worth a mention...

I would recommend setting <cfdump>'s in various locations where you'd expect the form values to exist, you should see a key "fieldnames" if you dump the form scope, and from there you can see exactly what is making it to where you want. Also it'll give you a pretty good indication as to if you're running the template/page you'd expect. Then "walk" the dumps back to the specific problematic location.

If you don't already have debugging turned on I would turn it on and follow the stack trace so you can see the flow of the request and where actions are being performed. This should significantly help you narrow your search to the location where you need to make a fix.

Its hard to help identify where your fields are getting lost without following the flow of your application, however I'd start where the error is occurring and place several dumps in between to get an idea of whats going on at each stage of the request. If you're working on a live site for whatever reason you can wrap it in a condition such as the one below so that you're the only one seeing the dumps...

<cfif CGI.REMOTE_ADDR eq "your ip address here">
 <cfdump var="#form#">
</cfif>

if you're not sure of your IP address, visit: http://whatismyipaddress.com/ 
Avatar of _agx_
_agx_
Flag of United States of America image

> I'm really curious to know why it worked in that case.

It is because one of those radio buttons is "checked" by default.  Since something is checked .. that field exists on the action page.

    <input type="radio" name="Title" value="Mme" id="Title" <cfif (#form.Title# EQ "Mme")>checked</cfif>

Also, trailblazzyr55's makes a good suggestion.  Another good starting point with forms is to dump the entire FORM scope at the top of the page. See what fields _were_ passed, and then work from there.
Avatar of Shawn
Shawn
Flag of Canada image

ASKER

<input type="radio" name="Title" value="Mme" id="Title" <cfif (#form.Title# EQ "Mme")>checked</cfif>

correct me if I'm wrong (need a coffee I think) but this line has no default check. It will however be checked if #form.Title# EQ "Mme"....when I submit the form with nothing checked it still passes.
Avatar of _agx_
_agx_
Flag of United States of America image

> It is because one of those radio buttons is "checked" by default.

Correction.  I take that back.  After looking at the form more closely, it seems like the reason is you may not be using "form.title" on the other action page.
Avatar of _agx_
_agx_
Flag of United States of America image

> correct me if I'm wrong

Nope. You are correct.  I looked closer at the sponsor action page and can't see a reference to "form.title". If it is not used, that would explain why the error doesn't occur.
Avatar of Shawn
Shawn
Flag of Canada image

ASKER

wow, never noticed that. good eye.

and you're right. As soon as I put

<cfparam name="form.title" default="use this value if it is not defined">

the error went away. thanks!

I just posted another question regarding a field in the same form...maybe you could help there too
https://www.experts-exchange.com/index.jsp?qid=24226247
Avatar of Shawn
Shawn
Flag of Canada image

ASKER

thanks for the pointers trailblazzyr55:.
I do have it debugging turned on but hadn't before used the <cfdump> before. That will surely save a lot of time in the future. thanks
Web Servers
Web Servers

A web server refers to the software that helps to deliver web content that can be accessed either through the Internet or through an intranet. The primary function of a web server is to store, process and deliver web pages to clients. The communication between client and server takes place using the Hypertext Transfer Protocol (HTTP). The most common use of web servers is to host websites, but there are other uses such as gaming, data storage, running enterprise applications, handling email, FTP, etc.

33K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo