CMB2
CMB2 copied to clipboard
Sending custom data through a hidden field
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.
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.
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?
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?