Skip Navigation

[Resolved] Adding a repeating field entry whilst preserving existing entries

This support ticket is created 6 years, 11 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

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

This topic contains 4 replies, has 3 voices.

Last updated by Nigel 6 years, 11 months ago.

Assisted by: Nigel.

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://toolset.com/documentation/programmer-reference/cred-api/

Thanks in advance 🙂

#526120

Minesh
Supporter

Languages: English (English )

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
Supporter

Languages: English (English )

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
Supporter

Languages: English (English ) Spanish (Español )

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?

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