0

I am having trouble passing an argument:

<cfset result = news.updateNews(form.id, form['title'&form.id])>

I am getting an error with that last argument, saying "Element title2 is undefined in a Java object of type class coldfusion.filter.FormScope.".

Any tips? What should the syntax be otherwise?

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
aceslowman
  • 621
  • 13
  • 28
  • 1
    cfdump `form['title'&form.id]` and see what is it? maybe you shall cfparam both with default values first? – Henry Jul 23 '12 at 17:14
  • 3
    I'd do a prior to your CFSET and first make sure that the variables you are expecting, are actually there. Just going off your error message it looks like you are expecting – Snipe656 Jul 23 '12 at 17:27

3 Answers3

5

The syntax provided expects that:

  1. You have an HTML form, and
  2. That form has a field in it named 'title2'

If you do not, it means you erroneously mixed your form.id (which is, in this example, '2') with the form field name 'title', creating the variable 'title2', which is expected to exist in the form scope (from your form submission).

If you do have a field named 'title2' in your form, your code will work. I personally tested it with this simple script of a form that posts to itself:

<cfif isDefined('form.submit')>
    <!--- here's your syntax --->
    <cfoutput>#form['title'&form.id]#</cfoutput>
</cfif>

<form action="form.cfm" method="post">
    <input type="hidden" name="id" value="2" />
    <input type="text" name="title2" value="" />
    <input type="submit" name="submit" />
</form>

You've somehow come up with an edge condition that may prevent the form field 'title2' from existing. Without further code or explanation, we can't really help beyond this.

Shawn Holmes
  • 3,752
  • 22
  • 25
  • Thanks! The problem ended up being that title2 was dependent on another field being defined, something I apparently overlooked. The syntax was ok though, so thank you guys. – aceslowman Jul 23 '12 at 17:49
0

Assuming the variables exist:

<cfset result = news.updateNews( form.id, evaluate('form.title#form.id#') ) >

Is one way to do it.

BKK
  • 2,073
  • 14
  • 17
  • I remember bracket notation being problematic in some dynamic evaluations (for example inside an evaluate or isDefined function) – BKK Jul 23 '12 at 17:27
0

You're passing in the member named "title2" of the'title'& stuct "form" which is the result of 'title'& form.I'd. If you're trying to pass in the form Id, just use form.Id without wrapping it in the form structure designator. If you are trying to pass in just a form input named 'title', just pass in form.title. If you're trying to pass both the form.id and form.title, pass them in separate parameters.

user1172456
  • 153
  • 2
  • 9