Home › Toolset Professional Support › [Resolved] Toolset edit form on submit count how many times has been changed.
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+00:00)
Tagged: Views, Views plugin
This topic contains 30 replies, has 2 voices.
Last updated by stuartm-2 5 years, 4 months ago.
Assisted by: Nigel.
Hello,
This is not an issue i just need some information or guidance.
I have an edit post Toolset form which only has one field with radio button.
What i would like to do on submit is to log how many times a change has been made to that field.
I know i can do that if i make parent - child connection and that form creates childs posts then show them with a view inside the parent post.
But i need that form to be Edit cause im using that radio field to filter inside a view and from what i heard from support is you cant filter based on a value of a child post.
Any guidance or idea is appreciated.
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Let me see if I understand this right.
You have some post type.
You have a form to edit posts of that type.
The form just includes a radio button (and submit), effectively a toggle.
Every time someone submits that form and has toggled the radio button you want to keep a running total of how many times that has happened. And you want to store that running total as a field against the post so that you can filter a View of such posts by how many times they have been toggled.
Is that right?
The radio button is a Types custom field, and stores some value, yes?
Apologies for the late reply.
Yes its a Types custom field. It has 3 values Pending which is default, Approved and Rejected their values are numbers 1,2 and 3.
Yes I have an edit form and every time they submit the choice i would like to keep a log inside the content template with a view that shows choice made and date.
Is there a way?
As i said before i tried to do this with create post form and connection parent - child (one to many) and i achieved what i wanted, but that stopped me from filtering parent posts based on that child value in another page so im using edit post form.
Many thanks
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
I assume this is a select field or similar rather than a radio field, which can only have two choices.
If I've understood you correctly, I'm not sure what you are gaining by creating a kind of log in the content that tracks each time the edit form is submitted and the value of the custom field when submitted.
How does the filter work?
Are you updating the status of this post and you want to filter by the *current* status, while also keeping track of the previous changes and states?
So the problem with your earlier solution, where you created a "log" child post was that you didn't know the current status of the parent post?
If that's the case I would persist with your earlier solution which I think is the best way for you to dynamically log the changes, and solve the filtering problem by duplicating the status custom field on the parent, which always has the current value, and which can be used in filtering.
So if you have a form to create child posts, add a code snippet that uses the cred_save_data hook to update the post meta of the parent post with the current status.
Have I understood the issue correctly?
Yes you have.
~So the problem with your earlier solution, where you created a "log" child post was that you didn't know the current status of the parent post?~
It just dosent work
Let me elaborate.
I have a view that has filters and one of them is filter by status which is all i need it to do.
Inside custom posts i have a form as you can see which toggles the status and that shows in the view.
If i want to change the approve or reject form to create posts lets say child Status and add that new view lets say logs inside the parent custom post, the filters in the pic status wont work anymore.
You are suggesting i create a duplicate custom field? How will that work?
Could you elaborate?
Many thanks
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Not exactly create a duplicate custom field.
Assign the same custom field to both the parent and the child post types.
When a user clicks to change the status of one of the posts in the table this is actually the form to create a child post.
You use the Forms API, i.e. the cred_save_data action, so that when a child post is created (with some value for the status custom field) you also update the same field on the parent post with the same value.
The parent post has values for that custom field, and so can be filtered by that custom field.
Sounds like a great solution! I know you dont support custom codes, is there an example or guidance where and how can i use cred_save_data action to make this work?
Many thanks this is very helpful.
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
There are some examples in the documentation for cred_save_data here: https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
I should be able to give you some more specific guidance a little later this morning...
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
I have a test site where I have a Project << Task relationship, where tasks have a priority field. I made that field available to projects as well, and then duplicated the field when submitting a task, copying it to the parent project with the following code:
add_action('cred_save_data', 'tssupp_form_submit', 10, 2); function tssupp_form_submit($post_id, $form_data) { // edit relationship slug and custom field slug $relationship = 'project-task'; $field = 'priority'; if (in_array($form_data['id'], array(91))) { // Edit form ID(s) if ( isset( $_POST['@'.$relationship.'_parent'] ) && isset( $_POST['wpcf-'.$field] ) ){ $parent_id = $_POST['@'.$relationship.'_parent']; update_post_meta( $parent_id, 'wpcf-'.$field, $_POST['wpcf-'.$field] ); } } }
You should just need to edit the slugs of the relationship and custom field, as well as the form ID.
Wow this works amazingly well!
Many thanks that you took the time to do this i appreciate it!
One last question if i want to show the file that needs to be approved or rejected inside the child posts which are shown inside a View should that be a nested view?
The file is uploaded through another form.
Basically in your example a task lets say has a custom field which gets filled by another form which is a file. And then you have to give priority to a task based on that file.
So you end up having Project << Task & a view created to show how many times priority field changed which is Task children.
My question is how do we assign a diffrent file inside the child [Task] for each child post, should that be a nested view?
Thank you for your time
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Am I to understand that the file field on the parent post may change, so a child post indicating a rejection may apply to a particular file, which is later changed and then the parent post may then get accepted, generating another child post.
And the child posts should each reference the relevant version of the file.
Effectively a kind of version control for the file attachments?
Exactly as you said. Thats the use case and process that we have.
A submit toolset form which adds a file for review - A review form which changes the status after watching the file and last a view which shows how many changes are made which are child posts created by that form.
In order to add the file submitted from another form should i create another relationship lets say the form with the file creates child posts of files submitted. Can that child added into the view -nested view maybe- that shows the status changes?
I hope im clearly understood.
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Maybe you want to do something similar to the previous step.
But instead of duplicating a field from parent to child, you want to make the file field available both on the parent and the child, and then when you use the form to generate a child post you get the value of the file field from the parent post and copy it to the child post.
Later you might update the parent post and change the file field, but the child post which logs the status can also keep a copy of the file.
Any problems with that solution?
In the previous step i did not duplicate the field as you told me i made it available to both. I tried that approach but it dosent show anything there.
How im gonna get that file field in that view?
Should the form that that adds the file be a create post child one?
At the the moment its an edit form for the parent post.
If you could help me solve the last piece of this puzzle would be much appreciated.
Many thanks
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Edit the custom field group so that the parent and child post types have the same fields available.
Then I envisage that you would add some code that hooks into the submission of the form to add a child post, similar to that above, but this time instead of copying the status field from the child post back to the parent, you copy the file field from the parent down to the child.
So you could edit the code to do both things. Something like this, based on my previous example:
add_action('cred_save_data', 'tssupp_form_submit', 10, 2); function tssupp_form_submit($post_id, $form_data) { // edit relationship slug and custom field slug $relationship = 'project-task'; $child_field = 'priority'; // (the field on the child to copy to the parent) $parent_field = 'file'; // (the field on the parent to copy to the child) if (in_array($form_data['id'], array(91))) { // Edit form ID(s) if ( isset( $_POST['@'.$relationship.'_parent'] ) ){ $parent_id = $_POST['@'.$relationship.'_parent']; // copy child field to the parent post if ( isset( $_POST['wpcf-'.$child_field] ) ){ update_post_meta( $parent_id, 'wpcf-'.$child_field, $_POST['wpcf-'.$child_field] ); } // copy the parent field to the child post $parent_value = get_post_meta( $parent_id, 'wpcf-'.$parent_field, true ); update_post_meta( $post_id, 'wpcf-'.$parent_field, $parent_value ); } } }