• Resolved Sylvain L

    (@reventlov)


    Hello,

    In a form, I have a group (called ‘4’) with several conditional radios (‘4-a’, ‘4b’ etc) : https://prnt.sc/SA4TkvaL9VQ3

    Only 1 radio is displayed (the one which is displayed depends of previous fields, conditional)

    But I need to get later in the form the value selected for the group 4. So sometimes it could be value selected in radio ‘4-b’, sometimes value selected in radio ‘4-e’ etc.

    I was thinking to use the hidden field to call this value. Is it possible ? If not, is a different method exist to retrieve a value in a single field ?

    Regards.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @reventlov

    I hope you are doing well today.

    This will be possible only with the HTML field. That HTML field can be hidden via CSS as we allow to add custom CSS class for each field. But as this is a repeater field it will take only value from 1st inside radio button and the rest of the repeaters will be skipped, based on my tests.

    If I get this right:

    1. above group field there is some radio button with 10 choices. Depend from item selected, you will show in group field some radio buttons
    2. later on you would like to have data what was selected and keep that value still before form is submit

    If so, as mentioned above, this will work only for 1st item from repeater or for multiple of them in case this will be out side that repeater.

    At this point it seems you will not show only 1 radio button in group field but many of them so in the end you would like to have mutliple values later on like:
    FOR ITEM 4: I WOULD LIKE TO REQUEST 4-C and 4-E

    Is that the main goal?

    Kind Regards,
    Kris

    Thread Starter Sylvain L

    (@reventlov)

    Hello,

    Thank you for your assistance. After some troubleshooting, we were able to resolve the issue we were having. Let me clarify what we were aiming for and how we solved it:

    Our goal was to have multiple radio button groups in our form (each group named “radio-2”, “radio-11”, “radio-10”, etc.) with each group having three possible options (H1, H2, H3). When a user selects an option from any of these groups, we wanted to record this value (H1, H2, or H3) somewhere in the form for later use.

    We solved this by using JavaScript/jQuery to attach an event listener to each radio button in each group. When a user selects an option, the script triggers a function that retrieves the value of the selected radio button (H1, H2, or H3) and stores it in a hidden text field (named “text-2”) in the form.

    The text field is made invisible to the user by a CSS class (“.hidden-field”) we applied to this field, with a matching CSS rule setting “display: none;” for elements with this class.

    This way, when the user submits the form, the value of the most recently selected radio button is included with the other form data and can be used as we wish.

    What we have done does not match the situation you described, as you were referring to a “repeater field”, where a single radio button group would be repeated multiple times. In our case, each radio button group is distinct and has its own name.

    I hope this clarifies our approach. Let me know if you have any other questions or suggestions.

    Best Regards,

    Plugin Support Adam – WPMU DEV Support

    (@wpmudev-support8)

    Hi @reventlov

    Thanks for response and explanation.

    It seem we misunderstood you initially, sorry about that!

    The solution which you came up with seems to be reasonable.

    You could simply use a HTML type field on the form instead and put all the radio fields in it – as HTML field can in real time show selected values of the other fields. But this wouldn’t “record the change” as HTML field is not saved in submission (it’s “infomrational”) only.

    A non-JS option could be also to use calculations instead, as follows:

    – in each of radio fields enable “calculations” option
    – and for each of the options set unique numerical value for calculations – in a way that each and every option of every radio field would have unique value across the form
    – add a calculation type field to the form
    – and then simply sum-up all the radio fields in it.

    Since only one radio button and one option can be submitted at the time, the resulting calculation value would always be unique then and point directly to selected option. But that wouldn’t save actual option but only corresponding number value. So it may require additional manual steps or code to re-use that (depending on “how” you are re-suing it).

    Otherwise, your JS solution would be the way to go then (and yes – it’s good that you actually use an input field hidden with CSS instead of core “hidden” field; because with “hidden” type field values are sanitized and if set with JS they wouldn’t be carried over with submission).

    Kind regards,
    Adam

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @reventlov,

    Since we haven’t heard from you for a while. I’ll mark this thread as resolved for now. Please feel free to re-open the thread if you need further assistance.

    Regards
    Nithin

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Call a value in an hidden field’ is closed to new replies.