Home › Toolset Professional Support › [Resolved] Problem with Credit_Save_data
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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
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/Karachi (GMT+05:00)
Tagged: Content-submission forms, Toolset Forms
Related documentation:
This topic contains 23 replies, has 3 voices.
Last updated by vijayB-4 5 years, 11 months ago.
Assisted by: Waqar.
Hi,
I am having this problem for a couple of weeks.
I had this piece of code which was working pretty well
add_action('cred_save_data', 'build_title', 10, 2);
function build_title($post_id, $formdata){
if ($formdata['id']==11856 or $formdata['id']==11862)
{
$title_arr = array();
$parent_id1 = get_post_meta($post_id, '_wpcf_belongs_swimmer_id', true);
$title_arr[] = get_the_title($parent_id1);
$parent_id2 = get_post_meta($post_id, '_wpcf_belongs_swim-event_id', true);
$title_arr[] = get_the_title($parent_id2);
$swim_race = get_the_terms( $post_id, 'swim-race' );
foreach($swim_race as $race){
$title_arr[] = $race->name;
}
$title = implode(' ', $title_arr);
$slug = sanitize_title($title);
wp_update_post(array('ID' => $post_id, 'post_title' => $title, 'post_name' => $slug));
}
if ($formdata['id']==11918 or $formdata['id']==11920)
{
$title_arr = array();
$parent_id1 = get_post_meta($post_id, '_wpcf_belongs_swimmer_id', true);
$title_arr[] = get_the_title($parent_id1);
$title_arr[] = get_post_meta($post_id, 'datapoints-start-date', true);
$title_arr[] = get_post_meta($post_id, 'datapoints-end-date', true);
$title = implode(' ', $title_arr);
$slug = sanitize_title($title);
wp_update_post(array('ID' => $post_id, 'post_title' => $title, 'post_name' => $slug));
}
if ($formdata['id']==11922 or $formdata['id']==11926)
{
$title_arr = array();
$parent_id1 = get_post_meta($post_id, '_wpcf_belongs_swimmer_id', true);
$title_arr[] = get_the_title($parent_id1);
$title_arr[] = get_post_meta($post_id, 'swimmer-body-date-of-measurement', true);
$title_arr[] = get_post_meta($post_id, 'swimmer-body-time-of-measurement', true);
$title = implode(' ', $title_arr);
$slug = sanitize_title($title);
wp_update_post(array('ID' => $post_id, 'post_title' => $title, 'post_name' => $slug));
}
if ($formdata['id']==11958)
{
$title_arr = array();
$parent_id1 = get_post_meta($post_id, '_wpcf_belongs_swimmer_id', true);
$title_arr[] = get_the_title($parent_id1);
$parent_id2 = get_post_meta($post_id, '_wpcf_belongs_swim-event_id', true);
$title_arr[] = get_the_title($parent_id2);
$title = implode(' ', $title_arr);
$slug = sanitize_title($title);
wp_update_post(array('ID' => $post_id, 'post_title' => $title, 'post_name' => $slug));
}
}
Now this function creates a title hence a swim time (timing for a swimmer) is stored like
Varun Patel Glenmark 72nd Senior National Aquatic Championships 2018 100 m Breaststroke
But now it is stored as
Add New Swim Time Add New Swim Time 100 m Breaststroke
The Crew form too input Data is 11856. Although when we save a time they post is displayed correctly (Attached screenshot)
Also the Edit Form was behaving erratically this morning wherein the swimmer's name and Event name (linked fields) were not displayed
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Hi there
From the code it looks like this is an older site built on Types 2 relationships, correct?
And have the relationships been migrated? (If you go to Toolset > Relationships do you see a list of relationships, or a prompt to run the migration?)
I think I will need a copy of your site to be able to do some testing to confirm what is going on.
Let me set up a private reply so that you can share that.
hidden link (you can exclude the uploads directory to reduce the package size).
Hi Nigel,
It seems to be working today but I really don't know what the problem is. I am trying to create a staging site and try to reproduce the problem
Vijay
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
OK, well let me know when you have something I can look at.
Hi Nigel,
I have not been able to reproduce the issue on my system but this is cropping up in my colleague's system and on my phone.
The CRED form does not show the linked fields.
Regarding the function it seems to work fine. Is there a tutorial on how to add Custom code in Toolset via a file?
Vijay
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
There is a documentation page about adding custom code here: https://toolset.com/documentation/adding-custom-code/
The issue of the empty parent select field is different, right?
Am I to understand that you are seeing it work on some devices/browsers, but not others?
At first glance that sounds like a browser caching issue—you should perform a hard reload and clear the cache on each device—but it's not clear how that could affect the options added to a select dropdown.
Did you create a staging site for testing?
Are you able to reproduce the problem on the staging site, on different devices?
Can you check the browser console for errors, and the debug logs for PHP errors?
On the staging site are you able to reproduce the problem if you disable non-Toolset plugins and switch theme to twentyseventeen?
Hi Nigel,
I have moved the code into a site specific plugin. All seems to work except that adding a new swim time the function does not work though it works while editing a time
Vijay
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Hi there
I still don't know whether this is using Types 2 relationships, migrated Types 2 relationships, or Types 3 relationships.
Maybe I could look at your site and I'll be able to see myself?
I will mark your next reply as private so that I can get log-in credentials from you—you may want to create a temporary admin user for me to use that you can later delete. And be sure to have a current backup of your site, even though I don't intend to make any changes.
What page will I find the form on?
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Hi Vijay
I couldn't get the FTP credentials to work and I need to use the debug logs, so I'm taking a clone of your site to install locally so that I can work on it more easily.
I'll get back to you.
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
I managed to install a copy of your site.
When I did I found the debug log filling up with lots of (unrelated) errors, you may want to investigate.
I stripped back the site to the essential plugins, and was then able to confirm the problem when submitting the form, that the custom code using the cred_save_data hook is not working.
We included a backwards-compatibility layer with Types 3 so that it shouldn't be necessary to modify such code for it to continue working, but it seems to be failing in this case at least.
I've escalated this with a copy of your site so that it can be looked into further.
In the meantime, if you didn't want to wait you would need to recreate your forms (if you auto-generate the forms the shortcodes for the parent select fields will be different), and then you would need to edit your code so that instead of using get_post_meta to retrieve the parent post ids, you would use the relationships API, and toolset_get_related_post (https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post).
Hi Nigel,
Am really not sure why the code is not working as it is working perfectly with the edit CRED form
Am a novice wrt coding and would really appreciate if ou could help me further with your suggested solution
Vijah
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
It shouldn't be necessary to make any changes, this is supposed to work and it looks like it stopped because we perhaps introduced a bug.
My colleague has already started debugging this, let's see what he says before having to change both your forms and your code.
Hi Nigel,
Any updates on this?
Vijay
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Hi Vijay
I checked the internal tickets and saw that the issue was debugged by support second tier and passed to the developers, but they have not proposed a solution yet. I have commented on that internal ticket to remind them that you are waiting on a solution, and when I get a reply I'll let you know.
Sorry for the wait.
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Hi Vijay
Just to let you know that this will be fixed in the next release (should be next week), but there is a solution described in this erratum which you can apply now if you want to: https://toolset.com/errata/access-relationships-after-submitting-a-form-no-longer-works/
Note that in either case you will need to modify your code so that it uses the cred_submit_complete hook instead of the cred_save_data hook.
The hook arguments are the same (https://toolset.com/documentation/programmer-reference/cred-api/#cred_submit_complete) so it should just be a matter of changing the name of the filter hooked into.