Skip Navigation

[Resolved] How can I programmatically update default value of a custom field?

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 3 replies, has 2 voices.

Last updated by Minesh 1 year, 5 months ago.

Assisted by: Minesh.

Author
Posts
#2621853

I would like to change the default value stored at custom field group level for a custom field.

Example - hidden link

How can I do this?

Use case -
1. I want to show one default value for starters
2. Then give user an option to change it.
2. If user changes it, the default value changes for all future transactions.
3. Now, next time the form is opened new default value up for a new post

I can do (1) and (3). But can't do (2) without updating the default value at custom field level.

#2622013

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

It seems to me based on the screenshot you shared that you want to update the default value of the custom field you added inside the custom field group.

There is no native way to do that as custom field group is stored as serialize array.

If you can tell me how exactly in what flow you want to update the custom field default value with what form and where you want to display it then I will be able to guide you in the right direction.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2622563

Yes. I would like to dynamically update the default value for a custom field in a specific field group.

Custom field stores the cookie.
If cookie stays the same -- no need to change.
If cookie expires, user should update it, which in turn should update the default value.
The scenario.
1. I want to provide users with a default value in the custom field
2. Default value should work most of the time and when the form submits, my custom code should be able to pick the default value
3. Because of (2), user does not need to enter data for the custom field in most cases.
4. But if the default value stops working, I want users to select an option in the form to not use default value and show the custom field. I have been able to show/hide custom field with conditionals
5. As custom field becomes visible, user should be able to change the value of custom field.
6. When user saves the form two things happen
6a. my custom code users the new value to process
6b. the default value in the custom field for the specific field group should change to the new value
7. (6b) is important because I don't want the user to enter the value in custom field if they don't need to and system should use the new default value as long as it works.

I hope this explains the use case.

#2622669

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Have you tried the form filter hook "cred_filter_field_before_add_to_form":
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_filter_field_before_add_to_form

The above hook will run before every field added to the form.

This filter enters into action before each field is added to a Form on the front-end of the site, and gives users the ability to modify several field attributes. Attributes vary by custom field type, so the examples here are generalized.

And there you can get the default value. Could you please check if above hook works for you or not?