CMB2 icon indicating copy to clipboard operation
CMB2 copied to clipboard

Sending custom data through a hidden field

Open M4N0JKUM4R opened this issue 1 year ago • 3 comments

image

I am creating a custom form that contains a mix of CMB2 fields and some fields created with JavaScript so that the user can calculate the price as they are not available in the CMB2 backend. I would like to send back the result of the calculations, let's say the dates, the time slots, and the price to hidden fields of the CMB2 form which will then be gathered on the next page for submissions. Can anyone advise what form of hidden field would be better in such a case? I could see two options so far:

Multiselect field - Send each slot data to one of the multiselect fields and insert it into the values.

WYSIWYG field - To return HTML as a whole.

What would be a better field of handling, in the case of CMB2 form? Any other ideas are appreciated as well.

Thanks.

M4N0JKUM4R avatar Dec 15 '23 08:12 M4N0JKUM4R

To be certain, are you asking just which would be better? or which would actually succeed? Asking because we may not be able to necessarily say which field type is best, as long as you're getting the data when you need it. However if they're not working, then that's more a troubleshooting question.

tw2113 avatar Dec 15 '23 14:12 tw2113

To be certain, are you asking just which would be better? or which would actually succeed? Asking because we may not be able to necessarily say which field type is best, as long as you're getting the data when you need it. However if they're not working, then that's more a troubleshooting question.

I just don't want to get into a rabbit hole :) I thought some people encountered such situations and had a hack one way or the other. What would be your plan of implementation?

M4N0JKUM4R avatar Dec 15 '23 15:12 M4N0JKUM4R

Not completely sure as I don't know all the details for this specific task for you.

That said, I am pretty sure hidden fields are essentially text fields that just aren't shown, so perhaps compile all the calculation fields into a serialized or json-ified array of data that can be appended to the hidden field for inclusion, and then on the server side when processing, unserialize/json decode the result and do what you will with it there?

tw2113 avatar Dec 15 '23 16:12 tw2113