Home › Toolset Professional Support › [Resolved] Using e-mail field results from a View to use as recipient list for a post 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 10 replies, has 2 voices.
Last updated by lesleeM 1 year, 4 months ago.
Assisted by: Minesh.
Minesh helped us set up a nested view to display on a page to show all our Ride Registrations, grouped by Ride Leader. That page is here:
hidden link
The views used to create this page are here:
Ride Registrations by Ride Leader Parent - hidden link
Ride Registrations by Ride Leader Child - hidden link
That page shows ALL registrations for ALL Ride Leaders.
After creating this page, I added my own view to add to each Ride Leader page to show all registrations for that specific Ride Leader.
An example of this can be seen here:
hidden link
And the view to create that is here:
Ride Leader Page - My Registrations - hidden link
What we would like to do now is to pull the e-mail address field from all the results on each single Ride Leader page to make them the recipients of a Post form submission. We did this previously with our Notification system on each Ride page pulling the registered e-mail addresses from each single Ride. Now we're trying to do this to add the same functionality pulling the registered e-mail addresses from each Ride Leader, so everyone registering for any Ride with that Ride Leader will get these Notifications.
We have a code snippet that accomplished this for us called notification-recipients. But I'm now having a problem with that snippet that is the subject of another active support ticket here:
https://toolset.com/forums/topic/errors-on-code-snippets-provided-previously/
I think that snippet just needs to be modified to pull from all Rides led by a single Ride Leader rather than from the individual Ride. This form will be put on the Ride Leader page and I have added a relationship between Ride Leader and Registration, so this should be doable.
Hello. Thank you for contacting the Toolset support.
First of all, I can see the issue with the code snippet "send-registration-notification-to-ride-leader":
The code added the the code snippet "send-registration-notification-to-ride-leader" is following:
if ( $form_id == 2083 && isset($notification['name']) && 'Ride Registration Notification' == $notification['name'] ) { // getting parent ride ID $ride_id = $_POST['_cred_cred_prefix_cred_container_id']; $ride_leader_posts = toolset_get_related_posts( // get posts related to this one $ride_id, // Relationship between the posts 'ride-ride-leader', // Additional arguments [ // Get posts where $writer is the parent in given relationship. // This is mandatory because we're passing just a single $writer post as the first parameter. 'query_by_role' => 'parent', 'role_to_return' => 'child', 'return' => 'post_id' ] ); foreach($ride_leader_posts as $ride_leader_id){ $address = get_post_meta($ride_leader_id, 'wpcf-ride-contact-email', true); if(!$address){ continue; } // Add a BCC to registration email $recipients[] = array( 'to' => 'to', 'address' => $address, ); } } return $recipients; }
I do not see to what hook/filter/action the above code belongs to? Can you please attach the above code to your desired hook/action first and correct it.
I tried to split that code from the snippet notification-recipients, but I messed up. See this support ticket for that:
https://toolset.com/forums/topic/errors-on-code-snippets-provided-previously/
Now both those snippets are giving errors and I don't know what I did wrong. I will not touch anything you guys have set up in there that is working again. I thought I'd be OK pulling that part you set up previously out. I only did so in an effort to avoid confusion for this ticket. I shouldn't have done that. Now the problem is much worse.
You or someone else must have changed something otherwise how can a working function suddenly stop working.
Like other tickets I have to adjust the code with other functions as well so there much be change in either of relationship or something else.
Now, can you please tell me what is now working on what URL and what related code you have added for the same.
I did try to change this. I apologize for that. I was trying to avoid confusion but ended up making things far worse. The code you had in there previously was doing two totally different things. We had one bit working, then I filed another support ticket for something else later, and you added a second bit of code within that same code snippet. But that second bit of code was for something completely unrelated to the first bit. At the time I didn't say anything because it worked and I didn't want to argue with success and ask for more from you.
But now that I'm asking about this, I thought that would cause confusion when filing this ticket because I only wanted to try to emulate what was done with the first part of it. So I tried to separate the two parts into two different snippets, which I did not do correctly, which caused errors. That's the ticket that Waqar is assigned to now. I also should have waited until Waqar was finished before filing this ticket. Sorry about that as well.
I'm just kind of flustered right now because I wasn't expecting to have all these functionality requests post-launch of the site. I thought everything was settled with pre-launch discussions. Once I'm rattled like this, i tend to make mistakes under pressure. I'm trying to keep up with having to help a bunch of end-users through different new processes with the new site while simultaneously now having to add this new functionality to keep some board members happy and I've made a mess of things here.
Once Waqar is done with the other ticket, then this ticket will be ready to be looked at. I'll reply again as soon as that one is resolved.
OK, the other ticket is resolved now.
So what I'm trying to do here is to add similar functionality to what is provided in the notification-recipients code snippet.
I've added the following post form to the Ride Leader template page:
hidden link
You can see it here:
hidden link
This is different from the post form used in the notification-recipients code snippet.
We want this post form to send to all the e-mail addresses pulled by this view:
hidden link
But it should also remove duplicates using the remove-duplicates-from-my-riders-view code snippet you set up.
Basically this is a form that will allow a Ride Leader to send a Notification to EVERYONE that has EVER registered for ANY of their rides. The previous functionality is Ride specific. The notification form is on the Ride page and it only sends to everyone that registered for that single Ride. This functionality allows Ride Leaders to send to everyone that has ever ridden with them.
The reason this needed is we have Ride Leaders that are rightly concerned that they have riders that ride with them every week that are not going to want to register every week for repeating rides. So if they send a Ride specific notification, there are riders have will not have registered for that week that they'll still want to notify. So by having this tool available as well, they'll be able to send to all riders that have ever registered for any of their rides.
Can you please send me admin access details and let me review your setup.
*** 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 have set the next reply to private which means only you and I have access to it.
I've adjusted the code added to the custom code snippet namely "notification-recipients" as given under:
add_filter('cred_notification_recipients', 'modify_recipients', 10, 4); function modify_recipients($recipients, $notification, $form_id, $post_id) { // Check notification name matches target notification if ( $form_id == 2327 && isset($notification['name']) && 'Ride Notification' == $notification['name'] ) { $ride_id = toolset_get_related_post($post_id, 'ride-notification'); $registration_posts = toolset_get_related_posts( // get posts related to this one $ride_id, // Relationship between the posts 'ride-registration', // Additional arguments [ // Get posts where $writer is the parent in given relationship. // This is mandatory because we're passing just a single $writer post as the first parameter. 'query_by_role' => 'parent', 'role_to_return' => 'child', 'return' => 'post_id' ] ); foreach($registration_posts as $registration_id){ $address = get_post_meta($registration_id, 'wpcf-email', true); $name = get_post_meta($registration_id, 'wpcf-name', true); if(!$address){ continue; } // Add a BCC to registration email $recipients[] = array( 'to' => 'bcc', 'address' => $address, 'name' => $name, ); } } else if ( $form_id == 8860 && isset($notification['name']) && 'Ride Notification' == $notification['name'] ) { global $post; /// getting view results $filtered_posts = get_view_query_results( 8433); foreach($filtered_posts as $k=>$v){ $address = get_post_meta($v->ID, 'wpcf-email', true); $name = get_post_meta($v->ID, 'wpcf-name', true); if(!$address){ continue; } $recipients[] = array( 'to' => 'to', 'address' => $address, 'name' => $name,); } } return $recipients; }
I've also added the email log plugin to check if emails were send or not and I can see it sends emails to all required emails successfully:
- hidden link
I deleted your first two notifications and kept the one titled cccc that worked with the mailing.
I looked at the e-mail log plugin you installed and can see that it sent to 9 addresses. But there are two that have the same address.
Toolset <kmjunk@cfl.rr.com>
Kenny <kmjunk@cfl.rr.com>
I just wanted to see where the Toolset one came from. When I look here:
hidden link
There isn't a new registration, but I know you have that already set to remove duplicates. When I look under Notifications | All Items in the dashboard, I'm not seeing an entry for Toolset.
So I was just wondering where that one came from first, and then I wanted to see if this could also be set to remove duplicate e-mail addresses.
Other than that minor issue, this is looking good.
For any further testing, please use the following Ride Leader page instead of the Kenny Moore one.
hidden link
Using this one, our test messages will only come to me instead of sending to all the other riders. I registered for one of the archived rides we have in the system just so we can test this there. The archived rides are not active on the site at this time.
I just did a test with that one and see that it sent to two addresses instead of just the one that is registered. So what I'm seeing is that this form is sending the notification first to the user account that is sending the notification and then adding all the registered e-mail addresses after that. That's OK to leave it like that if that is the case. That explains why the first one on your test went to Toolset <kmjunk@cfl.rr.com>. No problem with that even if it is a duplicate. I'm assuming that what you set up previously to remove duplicates is still working among the registered users because this did not send two Todd Green e-mails. It just doesn't apply to the sending user e-mail before the registered ones get added. If I'm correct with this, I think we're good to go. Let me know what you think on that before I mark this as resolved.
Yes - that's correct. You can test with other ride leader post and check otherwise as I shared the code works as expected.
My issue is resolved now. Thank you! All good here.