libreform / wp-libre-form

Easy native HTML5 forms for WordPress. Version 1.5 is unmaintained, but works without issue. 2.0 has been rewritten from the ground, and can be found at https://github.com/libreform/libreform
https://wordpress.org/plugins/wp-libre-form
GNU General Public License v3.0
67 stars 27 forks source link

extra custom attributes converted to false format #108

Closed despecial closed 6 years ago

despecial commented 6 years ago

https://github.com/libreform/wp-libre-form#adding-extra-attributes-to-the-form-element

Adding extra attributes to the form element You can add any custom attributes to the form element easily by adding them to the shortcode [libre-form id="1" data-custom-attr="contactme"] The attribute will render as is on the

element <form class="libre-form libre-form-1" data-custom-attr="contactme">

But when I try to add this: [libre-form id="39" data-abide novalidate xclass="hf_form"]

The output looks like this: <form data-form-id="39" class="libre-form libre-form-39 hf_form" 0="data-abide" 1="novalidate">

Instead of the desired html: <form data-abide novalidate class="hf_form">

k1sul1 commented 6 years ago

Must be a regression, I recall using this feature in the past successfully.

What happens if you add values to the attributes? Because it seems like the parsing function expects key-value arrays, instead of numerically indexed arrays, and when values are lacking, keys become values and numbers are used as keys.

This bug shouldn't be too hard to fix, feel free to give it a shot if you want to, I'll gladly merge it.

If not, we'll fix this before the new release comes out, which is when us maintainers have some time.

k1sul1 commented 6 years ago

https://github.com/libreform/wp-libre-form/blob/2b8efd882074a8c670394db1ba1b267adaee59f4/classes/class-cpt-wplf-form.php#L838-L841

We can't use null to remove values, because we need null for attributes without value. unset and so on.

despecial commented 6 years ago

Hey Christian, thanks for your feedback. I already looked into the code and added a new attribute for the shortcode.

[shortcode xhtml="data-abide novalidate"]

In the form output function, before the attributes loop, I extracted the value, removed it from the attributes array and echoed it to the form.

k1sul1 commented 6 years ago

Working on this now. It appears that you could've also used data-abide="" and novalidate="" as a workaround.