0

I am building a legacy widget where I need to access some checkbox values added to the DOM in runtime using client script. For example:

<input id="groups-2-523221" type="checkbox" value="523221" name="groups[]" />
<input id="groups-2-303393" type="checkbox" value="303393" name="groups[]" />

This is how it looks like:

enter image description here

In classic widget editor mode, I can grab the values successfully by iterating through the $_POST['groups'] array. However, $_POST['groups'] is inaccessible when placing the widget in the block widget editor.

I can understand that the reason is that form is not being "posted" physically. But I am unable to find a solution. What is the best way to accomplish this?

2
  • 1
    can you edit your question to include the code you're referring to as well as the surrounding code? It's not clear where and how you're using this, and there's almost no context for where your input tags are being shown in the code, or how your save method is structured to write an answer. Use the edit link underneath the tags
    – Tom J Nowell
    Commented Aug 21, 2023 at 8:41
  • Generally legacy widgets don't need to access $_POST, since that part of the process is handled by the WP_Widget class. Also, your field name is not unique, so multiple instances of the widget would interfere with each other. So it seems like you're doing something unusual here, and more context would be helpful. Commented Aug 21, 2023 at 15:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.