Error when posting form variables with - hyphen in name

216 views
Skip to first unread message

Michael Muller

unread,
Mar 14, 2015, 3:47:49 PM3/14/15
to lu...@googlegroups.com
I'm getting this error when posting a form variable that contains a hyphen - in the variable name:

invalid variable name declaration [form.verify-v1]

invalid variable name declaration [form.google-site-verification]

This error did not occur under ACF. Wondering if this is fixable, or should I just rename my variables?

Thanks,

Mik

Andrew Dixon

unread,
Mar 14, 2015, 3:52:25 PM3/14/15
to lu...@googlegroups.com
I'm surprised that ACF doesn't error with that. This will work for you however on both:

form['verify-v1']
form['google-site-verification']

Kind regards,

Andrew
about.me
mso - Lucee - Member

--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/151f23ee-0dd8-437b-b9ec-1b442210edf1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Peter Boughton

unread,
Mar 14, 2015, 4:11:44 PM3/14/15
to lu...@googlegroups.com
If your code contains the actual text "form.verify-v1" as a variable
then it would error in CF, and every CFML engine, because "-" cannot be
used there; it gets confused with the subtraction operator.

(This isn't unique to CFML. It's basically a result of ASCII only
having a single character for both hyphen and minus, along with spaces
being optional.)

The solution in CFML (works in all engines) is to replace the dot
notation with bracket notation, i.e:

form['verify-v1']
form['google-site-verification']

Note that this is also how you can do dynamic field names - the
contents of the brackets can be any expression which resolves to a
string, e.g:

if ( form.KeyExists('field_#i#') )
doSomethingWith( form['field_#i#'] )

Or:

form[ Something.getKeyName() ]

Michael Muller

unread,
Mar 20, 2015, 10:27:49 AM3/20/15
to lu...@googlegroups.com
That code ran for years under ACF9. It did not under Railo and now Lucee.  I will try the bracket approach. Thanks.

Mik Muller, president
Montague WebWorks
(413) 320-5336
http://www.MontagueWebWorks.com


--
You received this message because you are subscribed to a topic in the Google Groups "Lucee" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lucee/Tztxe_uQVQE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lucee+un...@googlegroups.com.

To post to this group, send email to lu...@googlegroups.com.

Robert Zehnder

unread,
Mar 20, 2015, 10:33:35 AM3/20/15
to lu...@googlegroups.com
I can verify it doesn't work under ACF 11. I hit this issue the other day :/

Adam Cameron

unread,
Mar 20, 2015, 10:47:03 AM3/20/15
to lu...@googlegroups.com


On Friday, 20 March 2015 14:27:49 UTC, Michael Muller wrote:
That code ran for years under ACF9. It did not under Railo and now Lucee.  I will try the bracket approach. Thanks.


Can you pls post some code (like a repro case / http://sscce.org/) that demonstrates that "working" on CF9?

-- 
Adam

Michael Muller

unread,
Mar 31, 2015, 11:17:17 AM3/31/15
to lu...@googlegroups.com

This did the trick. And the quotes made the difference. Thanks.

form['verify-v1']
form['google-site-verification']

Here's my original code. It broke on the third line, only when editing fields that had hyphens in it. This code ran for years under ACF9. Not sure why I have the magic.

<cfloop index="keys" list="#form.l_keylist#">
<cftry>
<cfparam name="form.#keys#" default="">
...


Michael Offner

unread,
Apr 2, 2015, 3:13:16 AM4/2/15
to lucee
so this is working on ACF
<cfparam name="form.a-b-c" default="">
and this breaks
<cfset form.a-b-c="">
peter did a perfect explanation why the second example cannot work.

Micha


--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.

To post to this group, send email to lu...@googlegroups.com.

Mik Muller

unread,
Apr 2, 2015, 8:38:12 AM4/2/15
to lu...@googlegroups.com
Interesting. Well, I wasn't doing a cfset on the var, just a cfparam and a read in a query, both of which worked in ACF. Anyway, it's fixed now.

Mik Muller
Sent from my iPad
You received this message because you are subscribed to a topic in the Google Groups "Lucee" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lucee/Tztxe_uQVQE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lucee+un...@googlegroups.com.

To post to this group, send email to lu...@googlegroups.com.

Walter Seethaler

unread,
Apr 2, 2015, 8:47:48 AM4/2/15
to lu...@googlegroups.com
As nobody has mentioned it yet. The ACF documentation contains the variable naming rules and hyphens are not allowed there. Even if it works, I wouldn't consider it stable.

  • A variable name must begin with a letter, underscore, or Unicode currency symbol.
  • The initial character can by followed by any number of letters, numbers, underscore characters, and Unicode currency symbols.

Mik Muller

unread,
Apr 2, 2015, 11:41:24 AM4/2/15
to lu...@googlegroups.com
Sure. Well, it wasn't intentional. I have a table of meta tag variables and values, making it easy to add new ones and update existing ones, and have them all just stuff into the head tag. These two variables in question are Google's. Being able to support their naming convention is handy.

Thanks,


Mik Muller
Sent from my iPad
Reply all
Reply to author
Forward
0 new messages