Skip Navigation

[Resolved] CRED 1.8.8 vs 1.9.2 ajax, post_id is not current post

This support ticket is created 7 years, 2 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.

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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 9 replies, has 3 voices.

Last updated by tinaH 6 years, 10 months ago.

Assisted by: Beda.

Author
Posts
#566547
before ajax save.png
following save mixup.png

There has been some change between Cred 1.8.8 and 1.9.2.

In CRED 1.8.8 I had a "new post" form on a single "event-plan" page.
This form was supposed to create a child post to "this" event-plan.
The form was set to "submit with Ajax" and "Keep displaying this form".
There was a hidden generic field that I used to set the post id for "this" event-plan.
When the form was submitted the form kept all field values and indicated that the post was saved.
After the form was submitted it kept the current post-id.
This way I could add multiple child-posts very quickly without having to reload the entire page and as the field values were kept I didn't have to re-enter values that were the same over and over again.

[cred_generic_field field='_wpcf_belongs_event-plan_id' type='textfield' class='classname' urlparam='']
{
"required":1,
"validate_format":1,
"disabled":1,
"default":"[wpv-post-id]"
}
[/cred_generic_field]

With the update to 1.9.2 there has been some changes.
The field values are removed after save.
The value in the hidden field is removed and replaced with the field value of the post that was just created which creates a post relation to the previous child-post rather than the current post. (See images). Only the first post is correctly set as a child-post.
I am no longer able to enter multiple child-posts without having to reload the entire page because of the post-id mess.
I can no longer use Ajax.
I have to re-enter values that was previously kept after ajax submission.

#566550

Forgot to add that this form has worked without any problems with CRED 1.8.8
There is an error in my comment on the image. The form does not save the post-title it saves the post-id of the post that was just created. Sorry for the confusion.

#566567

I can add my own JS to solve it but I need to know the name of the CRED ajax save, js event.

#566675

We should clear all fields or values.
We should clear the form, so to have it ready for new Posts.

That means it is correct that Fields that have originally no default value or so, are empty on a Form.
And that will be empty after an AJAX Submit.

What is not correct, is that some data from any other post, even current post, is mistakenly used to populate Fields that, on a "new post" form, should be empty (even after AJAX Submit).

I have investigated and updated the DEV in regard.

I see the issue you mention. You use the Post ID shortcode, that loads the current page ID, and after the AJAX action, the ID is the ID of the created post instead of the Current Post.
And that should mean, we do not properly clean the form (reset) it after AJAX.

You could use Custom Code, a CRED API filter, that allows the usage of a "container_id".
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

This allows you to get the ID of the Post where the CRED is inserted to.
Then, with the filter you can update the data of the created post, as example, it's parent post ID Field.

The more appropriate method would also be, to populate the Parent Post Picker in the CRED Form with the Post ID ShortCode in the value attribute, but it's also not working now, due to the same issue as you encounter in the generic Field.

But that, after we fix the issue, should be the recommended way to go.

#566719

I created a simple ajaxStop event that updates the value from a data-attribute while I wait for a fix for this problem.
Will you update this ticket when the problem is solved?

#578152

For anyone having the same issue, while waiting for a proper solution.
ajaxStop() event does not work anymore but I found this event in the support forum that does.

jQuery(document).on('js_event_cred_ajax_form_response_completed', function (e) {
//do something
});

#600394

Minesh
Supporter

Languages: English (English )

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

We publish errata for this issue and I would like to update you that this issue will be fixed in next CRED official release:
=> https://toolset.com/errata/cred-is-not-fully-resetting-the-post-object-when-a-form-is-sent-with-ajax/

#601103

We have an errata for this, but it does not yet provide the solution.
You can follow the errata thou, to be notified when it's released (next CRED Release).
https://toolset.com/errata/cred-is-not-fully-resetting-the-post-object-when-a-form-is-sent-with-ajax/

Thank you!

#605972

This is solved in CRED 1.9.4

If you encounter more issues, please report them to us in new tickets.

Thank you

#607940

Confirmed. Problem gone in latest release 🙂