Error when posting form variables with - hyphen in name

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

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 http://about.me/andrew_dixon
mso http://www.mso.net - Lucee http://lucee.org - MemberOn 14 March 2015 at 19:47, Michael Muller <@Michael_Muller> wrote:

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


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+unsubscribe@googlegroups.com.
To post to this group, send email to lucee@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/lucee/151f23ee-0dd8-437b-b9ec-1b442210edf1%40googlegroups.com
https://groups.google.com/d/msgid/lucee/151f23ee-0dd8-437b-b9ec-1b442210edf1%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

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() ]

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?On Friday, 20 March 2015 14:27:49 UTC, Michael Muller wrote:


Adam

I can verify it doesn’t work under ACF 11. I hit this issue the other day :/On Friday, March 20, 2015 at 10:27:49 AM UTC-4, 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.

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

On Sat, Mar 14, 2015 at 4:11 PM, Peter Boughton <lu...@sorcerersisle.com <javascript:>> wrote:

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() ]


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 <javascript:>.
To post to this group, send email to lu...@googlegroups.com <javascript:>
.
To view this discussion on the web visit
https://groups.google.com/d/msgid/lucee/20150314201137.00000c88%40sorcerersisle.com
.
For more options, visit https://groups.google.com/d/optout.

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.comOn Sat, Mar 14, 2015 at 4:11 PM, Peter Boughton <@Peter_Boughton> wrote:

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() ]


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+unsubscribe@googlegroups.com.
To post to this group, send email to lucee@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/lucee/20150314201137.00000c88%40sorcerersisle.com
.
For more options, visit https://groups.google.com/d/optout.

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.

...

so this is working on ACF

and this breaks

peter did a perfect explanation why the second example cannot work.

MichaOn Tue, Mar 31, 2015 at 5:17 PM, Michael Muller <@Michael_Muller> wrote:

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.

...


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+unsubscribe@googlegroups.com.
To post to this group, send email to lucee@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/lucee/6fc6a229-e6bb-48d8-8559-6b15d80d029f%40googlegroups.com
https://groups.google.com/d/msgid/lucee/6fc6a229-e6bb-48d8-8559-6b15d80d029f%40googlegroups.com?utm_medium=email&utm_source=footer
.

For more options, visit https://groups.google.com/d/optout.

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
413-320-5336
http://MontagueWebWorks.comSent from my iPad

On Apr 2, 2015, at 8:47 AM, Walter Seethaler <@Walter_Seethaler> wrote:

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.

https://wikidocs.adobe.com/wiki/display/coldfusionen/Creating+variables

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.

Am Donnerstag, 2. April 2015 14:38:12 UTC+2 schrieb Michael Muller:

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
413-320-5336
http://MontagueWebWorks.com
Sent from my iPad

On Apr 2, 2015, at 3:13 AM, Michael Offner mic...@lucee.org wrote:

so this is working on ACF

and this breaks

peter did a perfect explanation why the second example cannot work.

Micha

On Tue, Mar 31, 2015 at 5:17 PM, Michael Muller mikinm...@gmail.com wrote:

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.

...


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/6fc6a229-e6bb-48d8-8559-6b15d80d029f%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


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.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/CAG%2BEEBy-6ZbAOswaBWLWMkRG%2BZiWGJBjb3EYAn0j2vHYt0SQhw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


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+unsubscribe@googlegroups.com.
To post to this group, send email to lucee@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/b285477b-b19f-4a42-950a-aeb9172a1b8c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

BTW, this tripped an error on Lucee 5.3.8.206, even using underscores, so it’s not just the - sign, unless Lucee considers underscore _ to also be a mathematical operator.

This works: <cfparam name="form['#ID#_newstyle']" default="">
This does not: <cfparam name="form.#ID#_newstyle" default="">

Oddly enough, this DOES work: evaluate("form.#ID#_newstyle")  soooooo, go figure.

Whats about avoiding the number signs # for output, pushing the variable name outside of quotes, (instead of StructVariable[“variable#id#”]) like so?

<cfscript>
structVariable={ 
    variable1: "one",
    variable2: "two",
    variable3: "one",
}
Id=2;
WriteDump( StructVariable["variable" & id]);

I like this more, it’s more similar to JavaScript.

Or if you like causing people to scream when they look at your code you could use the CHR tag

<cfparam name='form#Chr(91)#'#ID#_newstyle'#Chr(93)#" default=#Chr(34)##Chr(34)#'>
1 Like