Skip Navigation

[Resolved] Default parameter in Cred generic field

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

Problem:

I have created a Cred with 3 generic fields : image, checkboxes and wysiwyg.

How to populate them with default value?

Solution:

You just need to output those field values as correspond format:

- image field: image file URL format

- checkboxes field: option's values format

- wysiwyg field: text value

For example:

https://toolset.com/forums/topic/default-parameter-in-cred-generic-field/#post-1254631

Relevant Documentation:

This support ticket is created 5 years, 7 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/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 8 replies, has 2 voices.

Last updated by Pat 5 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#1254631

Pat

Hello,

I have created a Cred with 3 generic fields : image, checkboxes and wysiwyg.

Now, I searching to populate them with default value. Can you explain me how I can format these values fr each of the field type?

<div class="form-group">
	<label>Photo</label>
        [cred_generic_field type='textfield' field='photo']
{
"required":0,
"default":"[types termmeta='photo-intervenant'][/types]"
}
[/cred_generic_field]      
</div>
<div class="form-group">
	<label>Secteur d'intervention</label>
       [cred_generic_field type='checkboxes' field='type']
{
"default":"[types termmeta='type-d-intervenant' ]",
"options":[{"value":"Conférencier","label":"Conférencier"},{"value":"Accompagnateur","label":"Accompagnateur"},{"value":"Formateur","label":"Formateur"},{"value":"Personnel CU","label":"Personnel CU"}]
}
[/cred_generic_field]
     
</div>
<div class="form-group">
	<label>Description</label>
        [cred_generic_field type='wysiwyg' field='description']
{
"required":1,
"default":"[types termmeta='description-intervenant'][/types]"
}
[/cred_generic_field]
	</div>

I have tried to place same kind of custom field :
'photo-intervenant' is an image field
'type-d-intervenant' is a checkboxes field
'description-intervenant' is a wysiwyg field

but this is not working.

Any idea?
Regards
Pat

#1254713

Dear Pat,

Where do you display the Toolset form?

Those Types shortcodes:
- [types termmeta='photo-intervenant'][/types]
- [types termmeta='type-d-intervenant' ][/types]
- [types termmeta='description-intervenant'][/types]
Works only in a taxonomy loop.

You can try to display above shortcodes directly, make sure all of them outputs correct results.

1) image field
You can populate it with the image URL format, for example:

[cred_generic_field type='textfield' field='photo']
{
"required":0,
"default":"<em><u>hidden link</u></em>"
}
[/cred_generic_field] 

2) checkboxes field
You can populate it with the option's value, for example:

[cred_generic_field type='checkboxes' field='type']
{
"default":["Conférencier", "Accompagnateur"],
"options":[{"value":"Conférencier","label":"Conférencier"},{"value":"Accompagnateur","label":"Accompagnateur"},{"value":"Formateur","label":"Formateur"},{"value":"Personnel CU","label":"Personnel CU"}]
}
[/cred_generic_field]

3) wysiwyg field
You can populate it with the text format, for example:

[cred_generic_field type='wysiwyg' field='description']
{
"required":1,
"default":"abcde12345"
}
[/cred_generic_field]
#1254727

Pat

Hi Luo,

Thanks for your answer.

I need to populate the generic fields by default with the content of some meta terms. That's working fine when meta are textfield but I have not found how to make it work with other kind of field type.

This is not an issue related on where I place the shortcode as for textfield, this is working fine. In fact, I'm in an Taxonomy Views and the meta are related to the taxonomy which is in the current loop.

Regards
Pat

#1254757

I have already tested above shortcodes in my localhost, they works fine:
https://toolset.com/forums/topic/default-parameter-in-cred-generic-field/#post-1254713

You just need to output those term's field values as correspond format:
- image field: image file URL format
- checkboxes field: option's values format
- wysiwyg field: text value

You need to make sure those shortcodes [types ...] do output values in correct values.

#1254869

Pat

Hi Luo,

I have checked that the correct value are displayed (I placed the same types shortcode I put as default before the generic cred and I can see it without any issue. It is just when I place it inside the "default" parameter that this is not working.

In the opposite, if I place some text, or some url ... in the default parameter (as you did in your example) of the generic field, this is working.
For some reason, only if the Types shortcode is placed, the default in not taken into account and nothing is displayed in the front end (meaning, the generic cred is not displayed at all).

Regards
Pat

#1256483

The problem you mentioned above is abnormal, please check these:
1) Make sure you are using the latest version of Toolset plugins, you can download them here:
https://toolset.com/account/downloads/

2) In case it is a compatibility problem, please deactivate all other plugins, and switch to wordpress default theme 2019, deactivate all custom PHP/JS code snippets, and test again

3) Also check if there is any PHP/JS error in your website:
https://toolset.com/documentation/programmer-reference/debugging-sites-built-with-toolset/

4) If the problem still persists, please provide database dump file(ZIP file) of your website, also point out the problem page URL and form URL, I need to test and debug it in my localhost, thanks
https://toolset.com/faq/provide-supporters-copy-site/

#1256763

Thanks for the details, I am download your database dump file, will update here if there is anything found

#1257757
generic-fields.JPG

The trick you mentioned above will break Forms generic shortcode, I suggest you try these:
1) Checkboxes field:

[cred_generic_field type='checkboxes' field='type']
{
"default":["[types termmeta='type-d-intervenant' ][/types]"],
"options":[{"value":"Conférencier","label":"Conférencier"},{"value":"Accompagnateur","label":"Accompagnateur"},{"value":"Formateur","label":"Formateur"},{"value":"Personnel CU","label":"Personnel CU"}]
}
[/cred_generic_field]

2) wysiwyg field:

[cred_generic_field type='wysiwyg' field='description']
{
"required":1,
"default":"[types termmeta='description-intervenant' output='raw'][/types]"
}
[/cred_generic_field]

I have tried them with your database dump file, both of them work fine, see screenshot generic-fields.JPG

#1266461

Pat

Hi Luo,

That's fine with me. Many thanks
Pat