Home › Toolset Professional Support › [Resolved] Incorrect notification being sent from a CRED Edit form
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 |
---|---|---|---|---|---|---|
- | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10: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/Kolkata (GMT+05:30)
This topic contains 13 replies, has 1 voice.
Last updated by simonM-5 2 weeks, 2 days ago.
Assisted by: Minesh.
Hi Support
I recently "replaced" a custom field on a form "Post Form - Edit Job Ad (ID: 931)" with the standard post_content field.
All works well, except that the notification being sent out is incorrect - the notification being generated is from the 2nd post in the list of posts by post author.
You can log in and reproduce yourself in our dev environment and see the emails produced in our SMTP log:
Steps to reproduce:
1) Log in as user: access details removed (*** PLEASE DELETE ONCE NOTED ***)
2) Click Ads in the menu (hidden link) to go to the list of ads by post author sorted by modified descending. The page contains the View
"Edit My Job Ads View" edit-my-job-ads-view
3) Click the button "Edit Job Ad" to edit the first one, and make an edit to the large text field at the bottom
4) Submit the form. View the email sent out here: hidden link
As you can see, the email is taking the post id of the first but one (ie the second) item in the list and sending the information from THAT post, rather than from the ID of the first post which you have just edited.
Any ideas what's going wrong here?
Kind regards
Simon
Hello. Thank you for contacting the Toolset support.
Do you mean that the job you edit is edited successfully but the email configured with form is not displaying the correct content belongs to the edited job?
If that correct - when I checked your form - I can see that you are using the following form:
=> hidden link
I also see you are using the following as email body:
[wpv-view name="job-ad-created-by-post-author" cached="off"]
To reference the post ID in email notification - you will have to use:
[wpv-post-id item="%%POST_ID%%"]
More info:
- https://toolset.com/course-lesson/send-notifications-when-someone-submits-the-form/#displaying-post-information-in-notifications
- https://toolset.com/documentation/programmer-reference/forms/how-to-use-custom-placeholders-in-cred-notifications/#using-standard-placeholders
HI Minesh
Happy New Year!
Yes, I mean that the notification is sending the information from the wrong post, not from the post being edited. It is taking the info from the 2nd item in the list of Job Ads.
The notifications were working fine, I only changed one field in the view, which was not even related to the post ID. The only thing I changed in the view was replacing the custom field
[types field='family-we-are-looking-for'][/types]
with
[wpv-post-body view_template="None"]
Otherwise the view is unchanged.
Kind regards
Simon
What if you try to change shortcode you changed from:
[wpv-post-body view_template="None"]
To:
[wpv-post-body view_template="None" item="%%POST_ID%%"]
Does that helps to fix the issue?
HI Minesh
I tried replacing that code and cleared the WP Cache and retested, it didn't work, but I believe that change would not achieve the desired results anyway. It would only change the information for that field within the view. However the view is retrieving ALL the false information, since it is picking up the wrong ID and showing all the field information from that post rather than the post ID being edited.
Kind regards
Simon
I see you are using the following view within the email notification body:
- hidden link
To get the ID of the post edited by user - you will have to use the placeholder <storng>%%POST_ID%%
I see with the above view you added the query filter:
Post author filter
Select posts with the author the same as the current logged in user.
I would like to know are you usting the above view elsewhere? if no:
Then what if you try to add post ID query filter to your view filter by shortcode attribute.
For example:
Post ID filter
Include only posts with IDs set by the View shortcode attribute "ids" eg. [wpv-view name="view-name" ids="1"]
More info:
- https://toolset.com/course-lesson/filtering-custom-lists-of-posts/#filtering-by-post-id
And then withiin your form's email notificaiton body - try to change the view's shortcode as given under where we pass the post ID placeholder with view's shortcode attribute "ids":
[wpv-view name="job-ad-created-by-post-author" cached="off" ids="%%POST_ID%%"]
Hi Minesh
I tried your suggestion, but then I get "No items found" in the email notification. So that suggests to me that that method is not passing the correct ID to the View in the notification either.
What perplexes me is that I just changed one field in the view, which was working fine before. I think we need to get to the bottom of why it is picking up the ID from the 2nd post in the list of Ads shown to the user (given by edit-my-job-ads-view) hidden link
Kind regards
Simon
The following view:
- hidden link
Are you using the above view within only email notification or elsewhere as well?
Why you added post author is current loggedin user? Waht if you try to remove that Query filter from above view and check?
Hi Minesh
As far as I am aware, it is just used within the notification, however, i believe the Query Filter is justified as it is, since when the user is editing their post, I want to ensure that the view is just retrieving THAT user's Job Ads, and that only the changes from the post which was last modified by the user.
Any further ideas why the wrong ID is being picked up in the first place? This all worked fine before I changed the view. It shouldn't break and start picking up the wrong ID just because I changed one field being retrieved in the view.
Thanks and regards
Simon
Well - first thing you should note down is that - we never encourage using View within the email notification. Also - you replaced the custom field with the content template I believe that is why the issue happen.
Fortunately I found workaround, I've created the following content template and move the view's shortcode to the following content template:
=> hidden link
[wpv-view name="job-ad-created-by-post-author" cached="off" ids="[wpv-attribute name='ids']"]
Now, I've added the above content teplate to your form's email notification section:
=> hidden link
[wpv-post-body view_template="ct-for-jobad-email-notification" ids="%%POST_ID%%"]
Can you please check now it works as expected.
Hi Minesh
"Well - first thing you should note down is that - we never encourage using View within the email notification."
My response:
If Views are "not encouraged" to be used in Email Notifications, then why is the option to add a View available? Either Views work or they don't, and the button should be there or not there and be supported or not supported accordingly. I've never come across this advice before.
I need to include at least some views to get other information, from other records created by the post author. Eg in the case of this ticket, a typical family user creates a user (wp_users), then the creates a post type family record (wp_posts, wp_postmeta), then the Job Ad (also wp_posts, wp_postmeta). The only link I have between all 3 is the post author.
Would it be valid then to include the other Views from the user and family data, but add the contents of the Job Ad record, directly in the Email notification? Your suggested solution seems to be complicating the process even further with extra Content Templates which were not necessary previously.
"Also - you replaced the custom field with the content template I believe that is why the issue happen."
My response:
I was following guidance found in other support tickets on populating the post_content field using generic fields, since we do not want the users to have a WYSIWYG editor:
Example post from Toolset forum:
https://toolset.com/forums/topic/disabling-rich-text-wysiwyg-editor-on-certain-forms-form-fields-completely/#post-1480753
In this post, you advised replacing the normal post content field with the code:
[cred_generic_field field='post_content' type='textarea' class='' urlparam=''] { "required":1, "validate_format":0, "default":"" } [/cred_generic_field]
In the same thread https://toolset.com/forums/topic/disabling-rich-text-wysiwyg-editor-on-certain-forms-form-fields-completely/page/2/#post-1482679, you advised to use the following code:
[wpv-post-body view_template="None"]
In another post from Nigel: https://toolset.com/forums/topic/disable-wysiwyg-editor-for-post-content-in-cred-forms/#post-2211943, which corresponds with a post from Waqar: https://toolset.com/forums/topic/how-to-disable-the-wysiwyg-editor/#post-2680931
they advise to use the following code in an Edit form:
[cred_generic_field type='textarea' field='post_content'] { "required":0, "default":"[wpv-post-body template='None']", "persist":1 } [/cred_generic_field]
Also Nigel advises to use a "persist" option, which is not present in your code. He says: "Note that where I added the generic field I included a "persist" option, which means that the field value will be saved. (Ordinarily they are not, and should be processed with server-side PHP using one of the Forms API hooks such as cred_save_data.)"
So I hope you can appreciate my confusion with the conflicting advice. Moving forward, what is correct? In your version, there is class='' and urlparam='', in Nigel's version not. In Nigel's version, the default is defined as "[wpv-post-body template='None']", in yours it's defined as "default":"".
In the documentation https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/#cred_generic_field, the following parameters are not explained:
- persist
- validate_format
Please provide clarification of
1) what the correct code is for capturing a large text field without the WYSIWYG editor into the post_content field in
a) a Post Form for creating content
b) a Post Form for editing content
Also please provide descriptions of what the "persist" and "validiate_format" arguments are designed to do, and whether they should be present in the Post Create Forms and/or the Post Edit Forms.
Thanks and kind regards
Simon
It seems you are moving in different direction. How you used post_content field using Generic field is fine. There is no issue with that.
In your case - as you edit the post and want to display the edit post information and for that as we have %%POST_ID%% that holds the ID of the post you edited using edit post form. As we already have information what ID you edited you do not have to use "view" - instead you can use the content template and add all information.
Why I used content template:
[wpv-post-body view_template="ct-for-jobad-email-notification" ids="%%POST_ID%%"]
As you do not have to do rework and you can use the view you created. The content template that will hold your view and passed the %%POST_ID%% (edit post ID) to content temmplate and later view will get that post ID we passed using %%POST_ID%% (edit post ID).
I hope that makese sense. Please check the following Doc:
- https://toolset.com/course-lesson/send-notifications-when-someone-submits-the-form/#displaying-post-information-in-notifications
Hi Minesh
I just discovered the placeholder %%FORM_DATA%% which is doing exactly the job of the Views I created to send us admins the form content! Much more efficient. How long has that functionality been there!!? Could have saved me a lot of work...
Thanks and regards
Simon
%%FORM_DATA%% placeholder is been there since years but you can not modify anything that you can just display as it is.
Hi Minesh
OK, it must'nt have been there at the time when I started creating those Views, but anyway! I found a solution to the issue we were having.
Thanks and kind regards
Simon