[Waiting for user confirmation] Adding a repeating field entry whilst preserving existing entries

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.

Our next available supporter will answer your ticket in about 10.61 hours from now. Thank you for your understanding.

You are not logged in. You can view support threads, but not post.
If you are already logged in, please refresh your browser.

Related documentation: CRED API

This topic contains 4 replies, has 3 voices, and was last updated by  Nigel 4 days, 9 hours ago. The support staff assigned to this topic is Nigel.

Viewing 5 posts - 1 through 5 (of 5 total)
Author
Posts
#526015

My CPT is an application. The user submits the application which is then processed. The processing stage may take some time, during which the user may want to add further comments to that record. What I don't want is for the user to edit or delete the previous comments they have made, hence a normal implementation of a CRED form field is no good here.

The slug for this field is "caregiver-comments-application"

I have a form with which the user can edit their application. I have used a [types field=] to display previous comments. I have then created a generic field as follows:

[cred_generic_field field='caregiver-comments-application-add' type='textarea' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":"",
"persist":1
}
[/cred_generic_field]

I have a function that looks like this:

add_action('cred_save_data', 'add_caregiver_comment_to_application',10,2);
function add_caregiver_comment_to_application($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==6973)

{
if (isset($_POST['caregiver-comments-application-add']))
{
// add it to saved post meta
add_post_meta($post_id, '__caregiver-comments-application', $_POST['caregiver-comments-application-add'], true);
}
}
}

I borrowed the code above from here: https://wp-types.com/documentation/programmer-reference/cred-api/

Thanks in advance 🙂

#526120

Minesh
Forum moderator

Supporter languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

So - the code you added to your current theme's functions.php file do not work?

#526390

Hi Minesh, it definitely doesn't work 🙁

#526871

Minesh
Forum moderator

Supporter languages: English (English )

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

Could you please share problem URL and share one test case example what you want to hide and what you want to show and where?

Do you mean in admin section you do not want to allow to delete repeating field entry or on frontend?

*** 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 would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

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

#527397

Nigel
Forum moderator

Supporter languages: English (English ) Spanish (Español )

Supporter Timezone: Europe/London (GMT+01:00)

Hi Greig

Minesh is absent today so let me see if I can help you.

Looking at your code sample I can see two problems with your add_post_meta call.

1. The key for Types custom fields is the field slug with the prefix "wpcf-", so in your case that should be "wpcf-caregiver-comments-application"

2. The final argument is the $unique parameter and is set to 'true'. From the documentation: "When set to true, the custom field will not be added if the given key already exists among custom fields of the specified post." (https://codex.wordpress.org/Function_Reference/add_post_meta.) This should be set to false.

Can you try changing the above and see if it works?

Viewing 5 posts - 1 through 5 (of 5 total)

You are not logged in. You can view support threads, but not post.
If you are already logged in, please refresh your browser.

Known issues and their solutions

We document known issues and their solutions in Toolset erratas. Save time by checking there first and seeing if what you are facing is a known issue. This list is kept short. We do our best to resolve all known issues with every release of Toolset plugins.

Support Policy

Toolset staff will help you use the Toolset plugins correctly, provide any information you need, help troubleshoot problems and advice on best-practices.

Please make sure to issue only one topic per each support ticket.

For more information, read our full Customer Support Policy.

Need custom programming work for your site? Check out our certified partners.