Home Forums General Issues Issue with radio field type not saving selection & entering new choice instead


Issue with radio field type not saving selection & entering new choice instead

  • Hi. I’ve got an issue when using a radio field type. I’m not sure if it’s a bug, or a limitation with what I’m trying to achieve.

    I have a list of choices, where I specify both a “value” and a “label” for each. The value is a code snippet that creates a button with a custom link (see image1). I have done it this way as the Elementor plugin I use cannot dynamically reference choice field types for URLs. As you can see, I also have the “other” and “save other” options checked, to allow me to add more links directly from my wordpress posts.

    My issue occurs when I’m in a post and select one of the radio button options that I created above. After I save my choice and refresh the page, it ends up ignoring my selection and instead creating a new option using the button text name (see image2).

    I’m guessing there’s some conflict going on with the use of a code snippet as a value, but I’m not sure what it is.

    When I turn off the ability to add and save “other” values, it then seems to correctly save the radio value, but this makes it inconvenient as I need the option switched on.

    I’ve also tried disabling all other plugins as well, to check for any conflicts, but the issue persists. It seems to also happen with the “checkbox” field type as well.

    I’d much appreciate some guidance. Thanks.

  • I’m not sure what you’re trying to do but yeah, you can’t have HTML as input values. You need to use simple strings and then do a conditional query for the value string in your template, and output appropriate code.

  • Hi vipstephan,

    Thanks for the reply.

    To answer what I’m trying to do – I’m trying to have a dynamic way to change the URL of a button for each different post on my WordPress site. The element or plugin I use cannot reference “choice” field types for URLs, and since I don’t have the required programming knowledge to shortcake a solution, I have made an HTML code snippet to do the same thing.

    What I don’t understand about your help though is why I am able to use HTML as input values so long as the “other” and “save other” options are not selected. It seems like there is some kind of conflict between having the HTML code and “other” selected.

    Do you know why, or if there is a workaround I could implement? Cheers.

  • The problem is that when you use the “other” choice to allow custom entries what happens is that ACF compares the submitted values against the existing values. At this point the existing value is an unescaped html value while the submitted value has had the html escaped. The values do not match so ACF thinks it is a new value and then proceeds to save this new escaped value.

    This can be overcome by adding an acf/update_value filter ( with a priority of < 10 so that your filter can run before the built in ACF filter. In this filter you can then correct the submitted value to be correct HTML before ACF makes its comparison. However, you should be very careful doing so because this will allow users to submit HTML which could allow XSS attacks on your site.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Issue with radio field type not saving selection & entering new choice instead’ is closed to new replies.