Skip to main content
Inspiring
July 9, 2009
Question

Checking for posted form variables

  • July 9, 2009
  • 3 replies
  • 616 views

HI Folks,

I have some dynamically created form fields, and I'd like to check their posted.

<input type="text" name="comment#id#" id="comment#id#" value="" />

I'm checking their posted by using:

<cfloop list="#postedlist#" index="i">

<cfif isdefined(form["comment" & i])>display value</cfif>

</cfloop>

However, I get the error:

Parameter 1 of function isdefined must be a syntactically valid variable name.

Can anyone help?

Thankyou

    This topic has been closed for replies.

    3 replies

    Inspiring
    July 9, 2009

    You might prefer to use the StructKeyExists function.  All of the form variables et al are made available to you in an array or structure, and you can express your test as "does a member named 'field21' occur in that structure?"  Once you determine that it does, you can retrieve the value and deal with it.

    Bear in mind that browsers do vary as to exactly what form-fields they will or will not send you.  Be prepared to deal with empty-strings, and with situations like "the user set this form-field to an empty string, so the browser did|didn't decide to include that field in the POST data."  C'est la guerre...

    Inspiring
    July 9, 2009

    loop through your form and extract all the fields that start with comment.

    Known Participant
    July 9, 2009

    Hope this helps...

    <cfif isdefined("form.comment#i#")>