Can't cast Complex Object Type Struct to String

1,309 views
Skip to first unread message

Dominique Dupuis

unread,
Nov 7, 2015, 2:18:00 PM11/7/15
to Lucee
Hi,
Still ironing out thing from migrating my site from cf10 to lucee .

The latest issue is this error:
Lucee 4.5.1.024 Error (expression)
Message Can't cast Complex Object Type Struct to String
DetailUse Built-In-Function "serialize(Struct):String" to create a String from Struct

The code that get this error is:
<cfif isDefined('form.fieldnames')>
<!--- clean up form submissions --->
<cfloop list="#form.fieldnames#" index="f">
<!--- clean up each value --->
<cfset form[f] = Replace(form[f],"<","&lt;","all")>
<cfset form[f] = Replace(form[f],">","&gt;","all")>
<cfset form[f] = Replace(form[f],'"',"&quot;","all")>
</cfif>
</cfloop>
</cfif>

How do I fix this?
Thank you,
Dominique

Jon Clausen

unread,
Nov 7, 2015, 2:31:40 PM11/7/15
to lu...@googlegroups.com
First of all, there is an error in your code:  the </cfif> without an opening tag, inside the loop.  Fix that one before anything else.

Second.  It appears to me that the error is throwing because form.fieldnames is a struct, rather than a string.  Dump it to find out but, if it’s a struct, you’ll need to use <cfloop> via the collection parameters.

Jon
--
Love Lucee? Become a supporter and be part of the Lucee project today! - http://lucee.org/supporters/become-a-supporter.html
---
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/2ddd4613-cd9c-438d-8e79-d66c736f46ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gert Franz

unread,
Nov 7, 2015, 3:16:29 PM11/7/15
to lu...@googlegroups.com
The reason for this definitely is that some of the form keys contain structs. Like for instance if you click an image form button.
This is for the reason that acf is then sending the image button as form['image.x'] and y. They contain the position of the mouse, when clicked on the image button. So you should also check for whether a key contains a struct.

Just dump the form and then you'll see it.

Gert

Sent from somewhere on the road
--

Dominique Dupuis

unread,
Nov 7, 2015, 3:33:39 PM11/7/15
to Lucee
For the /cfif, sorry, I only forgot to remove it on pasting the code for the post That cfif tag was removed from the post since it had no relevance in the problem or in understanding the context.

As for the code itself, this is a reusable func to clean up form submissions. So form.fieldnames could be only one form field name (string) (lets say customer_note_name) , or a comma-delimited list of form field names, but still a string (like in the dump below).
In this case the <cfdump var="#form.fieldnames#"> returns: 
string: cw_customers_notes.customer_Note_date_added,cw_customers_notes,AddCustomerNote,customer_Note,customer_Note_status,customer_Note_origin,customer_id

Dominique

Dominique Dupuis

unread,
Nov 7, 2015, 3:53:35 PM11/7/15
to Lucee
Ha!  Got it. You are correct, the dump pointed me in the right direction. For some reason, this was writen:
 <input type="hidden" name="customer_note.customer_Note_date_added"  value="<cfoutput>#Now()#</cfoutput>">
Instead of:
 <input type="hidden" name="customer_Note_date_added"  value="<cfoutput>#Now()#</cfoutput>">
That fixed it.
Tks!
Dominique
Reply all
Reply to author
Forward
0 new messages