Skip Navigation

[Resolved] Saving generic checkbox for gdpr consent value to db

This support ticket is created 2 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Author
Posts
#2088019
Untitled-1.png

Hello
I created a generic checkbox for consent to the terms and the privacy policy for a user registration form. My problem is that in the user profile the checkbox doesn't appear checked and that means that it doesn't save the checked state. I copy the form code here and I also attach a screenshot of the user field.

[cred_generic_field type='checkbox' field='wpcf-consent']
{
"required":1,
"persist":1,
"default":1,
"label":"Sunt de acord cu <a href='<em><u>hidden link</u></em> și condițiile</a>, cu <a href='<em><u>hidden link</u></em> de confidențialitate</a> și îmi dau acordul pentru folosirea datelor mele personale pentru înregistrare."
}
[/cred_generic_field]
#2088319

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

The generic field option is used for virtual fields, that is for the fields which are not actually registered at Toolset -> Custom Fields.

As you want to store this consent confirmation in the database and have already registered a custom user field for this, in the user forms you'll use it as a regular field and not as a generic field.

Example:


[cred_field field='consent' force_type='field' class='form-control' output='bootstrap']

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2088353

Hi Waqar.

Then please tell me how can I use HTML in the checkbox label. I need to link the terms and conditions and the privacy policy in the checkbox label. I tried, but it strips out the html.

#2088371

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back.

I'm afraid, there is no built-in option available to achieve this, so it will require some workaround.

In your form's code below the consent field, you can include a special "span" tag and enclose the text and HTML content that you'd like to use with the field, within that span tag:

Example:


<span id="special-text" style="display:none;">Text and HTML for the label</span>

Please replace "Text and HTML for the label" with the actual text and HTML content.

And in the Form's JS editor, include the following custom script that will get the content from that special span tag and use it as the label for the consent field checkbox:


jQuery( document ).ready(function() {
	var txt = jQuery("span#special-text").html();
	jQuery(".wpt-form-set-checkboxes-wpcf-consent .wpt-form-item-checkbox label").html(txt);
});

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2090563

Thank you Waqar!
Could you help me to rewrite the jquery in a way that tha input is not disappearing too? It seems that the input tag is inside the label. hidden link

I also have a question related to this. You can see that above the consent I have two selects. The COUNTRY (Tara) select shows conditionally a corresponding generic field where I have the COUNTIES (Judet) as options separately for each country. I use the persist:1 and saves correctly the string in a simple user text field in the db. Is it alright to use this or should I have been using a jquery solution similar to the one you adviced me for the consent? I guess I've read somewhere that the persistent attribute is deprecated.

#2091577

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

For the case where the checkbox is inside the label tag, you can use a slightly updated custom script:


jQuery( document ).ready(function() {
    jQuery(".wpt-form-set-checkboxes-wpcf-consent .wpt-form-item-checkbox input").prependTo("span#special-text");
    var txt = jQuery("span#special-text").html();
    jQuery(".wpt-form-set-checkboxes-wpcf-consent .wpt-form-item-checkbox label").html(txt);
});

Although, the "persist" attribute currently works, it is no longer officially documented:
https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/#cred_generic_field

This is why, I'll not recommend using it and you should use a regular field in place of a generic field, when you need to save it's value.

#2094385

Thank you very much Waqar it's working prefectly!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.