Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending custom data through a hidden field #1505

Open
M4N0JKUM4R opened this issue Dec 15, 2023 · 3 comments
Open

Sending custom data through a hidden field #1505

M4N0JKUM4R opened this issue Dec 15, 2023 · 3 comments

Comments

@M4N0JKUM4R
Copy link

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.

@tw2113
Copy link
Contributor

tw2113 commented Dec 15, 2023

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.

@M4N0JKUM4R
Copy link
Author

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?

@tw2113
Copy link
Contributor

tw2113 commented Dec 15, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants