Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Getting Started / March 2007



Tip: Looking for answers? Try searching our database.

My FORM ELEMENT IS UNDIFINED

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
numerical07 - 30 Mar 2007 00:41 GMT
When I put  my form up in the browser, IF i dont check the Instock checkbox
then its undefined. If I check it, then it runs fine. Why is it undefined when
uncheck. How can I give my check box a default value without putting <cfif
undefined(form.instock)> make it defined</if> Is there something i can put into
the form to give it a default value

<table border="0" cellspacing="0" cellpadding="0" style="position:relative;
left:200px; ">
<cfform action="articlesuccess.cfm?sub=2" method="post"
enctype="multipart/form-data">
  <tr>
    <td width="139">Product Name: </td>
    <td width="317"><cfinput type="text" name="ProductName"></td>
  </tr>
  <tr>
    <td>Product Price: </td>
    <td><cfinput type="text" name="ProductPrice"></td>
  </tr>
  <tr>
      <td>Product Category:</td>
    <td><cfselect query="gotShopCat" display="ShopCatName" value="ShopCatID"
name="ShopcatName">#ShopCatName#</cfselect></td>
  </tr>
  <tr>
    <td>In Stock: </td>
    <td>Yes<cfinput type="checkbox" name="instock" value="yes">  </td>
  </tr>
  <tr>
      <td>Product Picture:</td>
    <td><cfinput name="ProductPic" type="file"> </td>
  </tr>
  <tr>
    <td valign="top">Product Description: </td>
    <td><cftextarea name="ProductDesc" cols="50" rows="10"></cftextarea></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><cfinput type="submit" name="submit" value="Submit"></td>
  </tr>
  </cfform>
</table>
Sojovi - 30 Mar 2007 01:03 GMT
Use <CFPARAM> for give a default value to undefined variables or the function
IsDefined that returns true or false is the variable passed as argument is
defined :
i.e. :
<CFPARAM name="FORM.instock" default="NO">

<CFIF IsDefined("FORM.instock") EQ False>
   ......
</CFIF>

Regards
numerical07 - 30 Mar 2007 01:40 GMT
Yea, I know how to do that, I was just wondering if there was a special attribute for the <cfinput type="textbox"> tag But I guess i can do that, thanks for the info.
numerical07 - 30 Mar 2007 02:00 GMT
Ok, I put a Isdefined function in there. I put it on the next page where the
CFC is invoked and the form values are inserted into a query. Keep in mind that
everything works when the checkbox checked (isdefined) . In bold below is where
i inserted it. It still doesnt work. it still says that my form.instock is
still not defined after i insert what is in bold

[b]<cfif NOT isdefined(FORM.Instock)>
<cfparam name="FORM>Instock" default="No">
</cfif>[/b]
<cfinvoke component="application" method="getcat" returnvariable="gotcat">
<cfinvoke component="application" method="ProductEntry"
returnvariable="success">
<cfinvokeargument name="Instock" value="#Trim(Form.Instock)#">
<cfinvokeargument name="ProductDesc" value="#Trim(Form.ProductDesc)#">
<cfinvokeargument name="ProductName" value="#Trim(Form.ProductName)#">
<cfinvokeargument name="ProductPic" value="#Trim(Form.ProductPic)#">
<cfinvokeargument name="ProductPrice" value="#Trim(Form.ProductPrice)#">
<cfinvokeargument name="ShopCatID" value="#Trim(Form.ShopCatName)#">
</cfinvoke>
cf_dev2 - 30 Mar 2007 03:17 GMT
>  It still doesnt work. it still says that my form.instock is still not defined
>  <cfif NOT isdefined(FORM.Instock)>

Looks like you didn't follow Sojovi's original example.  You left out the
double quotes around the variable name. From the documentation

[b]IsDefined("variable_name")[/b]
[b]Parameter:[/b] variable_name
[b]Decription:[/b] String, enclosed in quotation marks. Name of variable to
test for.

If you don't put the variable name in quotes, CF will treat it as a variable
and immediately attempt to evaluate it.
Sojovi - 30 Mar 2007 02:33 GMT
Seems to be that I didn't be clear enough.
First, the syntax is <cfparam name="FORM.Instock" default="No"> and not
<cfparam name="FORM>Instock" default="No"> (the > is incorrect)
<cfparam name="FORM.Instock" default="No">
is the same as using
<cfif NOT isdefined(FORM.Instock)>
    <cfset FORM.Instock="No">
</cfif>
And you put it at the top of the page, function of component.

Using :
<cfif NOT isdefined(FORM.Instock)>
    <cfparam name="FORM.Instock" default="No">
</cfif>
should work but is not the best coding.

Regards
Sojovi - 30 Mar 2007 02:36 GMT
Ah.. by the way.. the behaviour if an HTML checkbox (CFFINPUT generates an HTML
control) is to send the value when is checked, but if it's unchecked, don't
send even the control with an empty value (like a textbox)

Regards
numerical07 - 30 Mar 2007 02:46 GMT
First, the syntax is <cfparam name="FORM.Instock" default="No"> and not
<cfparam name="FORM>Instock" default="No"> (the > is incorrect)
<cfparam name="FORM.Instock" default="No">
              -Sojovi

Lets ignore the mistake I made. Cause when its corrected, its still saying
that the FORM.Instock is undefined.
47 : <cfif NOT isdefined(FORM.Instock)>
48 : <cfparam name="FORM.Instock" default="No">
49 : </cfif>

And you put it at the top of the page, function of component.
          -Sojovi

Why does it matter where I put it if the CF server is saying that immediately
after I submit the form, FORM.Instock is undefined.

Using :
<cfif NOT isdefined(FORM.Instock)>
<cfparam name="FORM.Instock" default="No">
</cfif>
should work but is not the best coding.
            -Sojovi

What is the best Coding then
Ken Ford - *ACE* - 30 Mar 2007 02:54 GMT
Try this:

<cfparam name="FORM.Instock" default="No">
<cfinvoke component="application" method="getcat" returnvariable="gotcat">
<cfinvoke component="application" method="ProductEntry" returnvariable="success">
 <cfinvokeargument name="Instock" value="#Trim(Form.Instock)#">
 <cfinvokeargument name="ProductDesc" value="#Trim(Form.ProductDesc)#">
 <cfinvokeargument name="ProductName" value="#Trim(Form.ProductName)#">
 <cfinvokeargument name="ProductPic" value="#Trim(Form.ProductPic)#">
 <cfinvokeargument name="ProductPrice" value="#Trim(Form.ProductPrice)#">
 <cfinvokeargument name="ShopCatID" value="#Trim(Form.ShopCatName)#">
</cfinvoke>

Signature

Ken Ford
Adobe Community Expert
Fordwebs, LLC
http://www.fordwebs.com

> First, the syntax is <cfparam name="FORM.Instock" default="No"> and not
> <cfparam name="FORM>Instock" default="No"> (the > is incorrect)
[quoted text clipped - 21 lines]
>
> What is the best Coding then
Sojovi - 30 Mar 2007 03:13 GMT
Take it easy man.. haha.. I'm not saying that you are stupid, just giving you
some tips to solve the problem.
If you put it like Ken said, it should work.  If not, try the :
<cfif NOT  isdefined(FORM.Instock)>
     <cfset FORM.Instock="No">
</cfif>

REgards
numerical07 - 30 Mar 2007 05:57 GMT
Good point cf_dev2. I didnt recognize the quotations in sojovi's first example.
Sorry about that sojovi, I was stupid about one thing, not paying close
attention. This isnt the first time I screwed that up. I always seem to screw
that up when for some dumb reason. Anyhow thanks everyone, i appreciate it
cf_dev2 - 30 Mar 2007 06:59 GMT
> is it possible to check if the actual value of a varible isdefined()

You have to call IsDefined() [i]first[/i]  then you can check the variable
value.  

<cfif IsDefined("form.myVariable") AND form.myVariable is "Articles">
   Yes, form.myVariable exists and its value is "Articles"
</cfif>

> if you take the quotations out then your evaluating the value,
> right ? If so, why would you do that.

I can't think of a reason.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.