I have a site running under apache with modphp that has been running reliably since 2012. It contains a static form with checkboxes that everyone uses and it always works just fine. A sample input element is:
<input type="checkbox" name="account_checks[]" id="account_checks-1" value="1" class="account_type_checkbox personal" />
<label for="account_checks-1">Horse Owner</label>
When submitted, $_POST contains an array named account_checks, with values that are the values of the value= attribute only for those checkboxes that were checked.
I just created another form that uses jQuery to generate some checkboxes dynamically. A sample input element is:
<input type="checkbox" name="excludedclassdivs[]" id="a-fun" value="a-fun"/>
<label for="a=fun">fun</label>
But when this form is submitted, $_POST does not contain any array named excludedclassdivs at all, regardless of how many boxes were checked.
I've read a number of other posts complaining about dynamically-created input elements not appearing in $_POST when a form gets submitted, but they all had various errors. I just cannot figure out what's wrong here. The form works fine and all of the input field values get submitted as expected. There are other text-type input elements on the page that are dynamically generated, but they all show up in $_POST as elements that are arrays named by the name= attribute (they all have names ending in [], making them post as arrays). Only the checkbox elements are missing. Any ideas?
BTW, in writing the sample input elements, I tried using Chrome's "View page source" feature to copy-paste, but that does does not show any of the input elements generated by jQuery. So I resorted to using Chrome's Inspect feature on the checkboxes, copy-pasting from there, lest I insert typos.
source https://stackoverflow.com/questions/76901282/checkbox-input-fields-added-with-javascript-not-being-submitted-with-the-form
No comments:
Post a Comment