Skip Navigation

[Resolved] Form Generic Field

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is that the user wanted to remove the labels from their single checkbox field.

Solution:

This can be done by using the code below.

add_filter('cred_filter_field_before_add_to_form', 'remove_cb_label', 10, 2);
function remove_cb_label($field, $computed_values){
  if(isset($field['id']) && in_array($field['id'], array('your-field-slug','field-slug2','field-slug-3'))){
    $field['title'] = '';
  }
  return $field;
}

Add the above to your Toolset custom code section in Toolset -> Settings -> Custom Code and just replace the field-slug options in the array with the slugs of your custom checkbox fields.

This support ticket is created 3 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 6 replies, has 2 voices.

Last updated by nicolaS-3 3 years, 10 months ago.

Assisted by: Shane.

Author
Posts
#1920699

Hi Shane, I have a couple of issues with forms: 1 generic fields (checkboxes) update correctly on user data but when I reopen the edit form they are all set as unselected. I applied this "default":"[wpv-post-field name='wpcf-okcontatto']", but still doesn't work.
2. recaptcha v2 doesn't appear on Toolset forms while it works perfectly on Avada forms. I applied this
{{cred_field field='recaptcha' class='form-control' output='bootstrap'}}
but the string appears instead of the recaptcha, see picture

#1920845
#1922023

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Nicola,

I'm spotting an issue here with this. The generic field doesn't have a state selector to set it to be checked on the backend.

This means that the value has to be selected on the frontend in order for it to work.

I know for the checkboxes group you can set a default value and it will automatically select the field on the frontend but for a single checkbox this is not the case.

Is there a reference link to the forum post where you've gotten this concept from so that I can have a look and see the field type they are using it on ?

Please let me know.

Thanks,
Shane

#1922173

Hi Shane,
I looked for the reference you are asking for but it's probably buried in one of my many previous support tickets and unfortunately I couldn't find it.
However, the issue above could be solved using normal checkbox fields, while the issue here is that for these fields the label can't be hidden. Digging for the reference I found this thread that could solve the label issue but the function code needs to be modified to be applicable to any checkbox, not just one. If you could do that, both backend setting and label would be solved, best option.
I cannot do it myself because I am not a PHP programmer.
Pls let me now
thanks
Regards
Nicola
https://toolset.com/forums/topic/how-to-hide-label-in-checkbox/

#1922259

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Nicola,

To get this issue clear, is it that you want to hide the checkbox labels ? I'm not too clear right now because the code that Christian provided is to hide the single checkbox label.

However your fields are checkboxes, the ones on the backend. You may need to recreate them individually as single checkbox and then add them back to your form, finally using the code to remove the labels and then you can add your own custom labels.

Please let me know if this is what you are trying to achieve.

Thanks,
Shane

#1922845

Hi Shane,
to make it clear I have prepared a custom form for you, go to this page:
hidden link

Yes ! I'd prefer to use the cred_field instead of generic fields, but the developers should give the opportunity to hide the field label in some ways, natively from a Toolset parameter. Alternatively I could use that PHP function above. But AFA I can see, the PHP function is made for one field only, if I have many checkboxes on the form I should set e one function for each one and this makes no sense ! Could you please change the function so that it applies to all checkboxes in the form ? or any better solution you might suggest.

Regards
Nicola

Good news: the recaptcha now works, there was an extra /DIV that was conflicting, removed that it appears ! great

#1923739

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Nicola,

Thank you for the clarity, unfortunately the hook only works for single checkbox so you will need to re-create your checkboxes group as a single checkbox then re-add them to the form.

Here is an example of the code that you will need to add to your site once you've recreated the fields.

add_filter('cred_filter_field_before_add_to_form', 'remove_cb_label', 10, 2);
function remove_cb_label($field, $computed_values){
  if(isset($field['id']) && in_array($field['id'], array('your-field-slug','field-slug2','field-slug-3'))){
    $field['title'] = '';
  }
  return $field;
}

So you will replace each of the following 'your-field-slug','field-slug2','field-slug-3' with the slug that is used for your field.

Once you've done this you should see that the labels have been removed and you can now add you custom labels. Just add the code to your toolset custom code section in Toolset -> Settings -> Custom Code and ensure that you've clicked activate on the code.

Thanks,
Shane

#1924337

My issue is resolved now. Thank you!