Home › Forums › Quform WordPress › Labels mismatch, dynamic server side validation and quform
- This topic has 1 reply, 2 voices, and was last updated 7 years, 2 months ago by
Ally.
- AuthorPosts
- February 8, 2018 at 1:36 am #24267
Hiyou
ParticipantHi, I’m using the following code for populating checkboxes server side:
add_action('quform_pre_display_1', function (Quform_Form $form) {
$select = $form->getElement('quform_1_3');if ($select) {
$options = array();
$posts = get_posts(array('numberposts' => -1, 'post_type' => 'travel'));foreach ($posts as $post) {
$options[] = array('label' => $post->post_title, 'value' => $post->post_title);
}$select->setOptions($options);
}
});
These generate the following code:
<div class="quform-options quform-cf quform-options-block">
<div class="quform-option"><input type="checkbox" name="quform_2_4[]" id="quform_2_4_097128_0" class="quform-field quform-field-checkbox quform-field-2_4 quform-field-2_4_0" value="119"><label for="quform_2_4_097128_0" class="quform-option-label quform-option-label-2_4_0"><span class="quform-option-text">Title 1</span></label></div>
<div class="quform-option"><input type="checkbox" name="quform_2_4[]" id="quform_2_4_097128_0" class="quform-field quform-field-checkbox quform-field-2_4 quform-field-2_4_0" value="120"><label for="quform_2_4_097128_0" class="quform-option-label quform-option-label-2_4_0"><span class="quform-option-text">Title 2</span></label></div>
<div class="quform-option"><input type="checkbox" name="quform_2_4[]" id="quform_2_4_097128_0" class="quform-field quform-field-checkbox quform-field-2_4 quform-field-2_4_0" value="121"><label for="quform_2_4_097128_0" class="quform-option-label quform-option-label-2_4_0"><span class="quform-option-text">Title 3</span></label></div>
<div class="quform-option"><input type="checkbox" name="quform_2_4[]" id="quform_2_4_097128_0" class="quform-field quform-field-checkbox quform-field-2_4 quform-field-2_4_0" value="122"><label for="quform_2_4_097128_0" class="quform-option-label quform-option-label-2_4_0"><span class="quform-option-text">Title 4</span></label></div>
</div>
I got 3 issues/questions here:
- Bug: When the checkboxes are generated, the labels for all the checkboxes are incorrectly pointing to the first checkbox, I realized all the Ids for the checkboxes are all the same – how do I fix this?
- I have to switch off client-side validation of values – if I need to do client-side validation, how do I do it via the hook even if I dynamically pre-populate the values?
- I can’t find complete documentation on what how the attributes of Quform_Form $form object passed in the filters are used. The online documentation seems very scarce in this area, is there any documentation you can share so it’s easy for me to use the available filters / hooks?
Thank you!
February 12, 2018 at 12:26 pm #24319Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
- AuthorPosts
- You must be logged in to reply to this topic.