I am making an event registration page (see screenshot).
I have CPT Event and Candidate with a many-to-many relationship.
I have made an event registration form using a CRED User Form.
- New users get a Candidate post and are registered for the Event using "cred_submit_complete".
- Existing users are registered for the Event using "cred_form_validate".
Registration is done with "toolset_connect_posts".
The first problem is that 'cred_form_validate' runs twice. This by itself is not a problem.
(Note: there is only 1 form on the page)
The main problem is that 'toolset_connect_posts' also runs twice and two identical connections are made.
For example: Candidate A gets two identical connections to Event B. (see the screenshot)
If I'm not mistaken then 'toolset_connect_posts' is not supposed to make double connections.
[08-Aug-2018 08:42:59 UTC] Filter triggered at 0.13696900 1533717779
So, confirmed, the filter only runs once.
If it is running twice on your site it must be something to do with your workflow or the custom code you added.
If toolset_connect_posts is duplicating the connection it must be because it is being called twice.
I'm not sure I understand the logic of
- New users get a Candidate post and are registered for the Event using "cred_submit_complete".
- Existing users are registered for the Event using "cred_form_validate".
Are you talking about separate forms for each scenario or are you trying to combine the functionality into a single form (which means *both* the cred_form_valiate and cred_submit_complete hooks will be triggered, which may account for your code running twice).
Anyway, you will need to revise your workflow to understand why you have code running twice.
1. There are no problems with new users if both "cred_form_valiate" and "cred_submit_complete" are enabled. In my code above you can see that "toolset_connect_posts" in "cred_form_valiate" only runs if a user exists.
The problem is when an existing user registers for the event, then "toolset_connect_posts" in "cred_form_valiate" only fires.
2. I have disabled all plugins except for Toolset and Code Snippets.
And I have disabled all code snippets except for the one below
I have found another problem when I try to check if the connection exists between the candidate and the event in "cred_form_validate" as below:
// Check if candidate already has event connection
$events = toolset_get_related_posts(
$candidate_id,
'candidate-event',
'parent'
);
if ( !in_array($event_id, $events) ) {
// Connect candidate and event if the connection doesn't exists
toolset_connect_posts( 'candidate-event', $candidate_id, $event_id );
}
The second time that "cred_form_validate" runs, there still isn't a connection that was made in the first run.
But after "cred_form_valiate" has finished there are two connections after all!
I tried "cred_form_validate" on another website and there is no problem on that website.
On the website with the problem I disabled all other plugins except for Toolset Forms. Furthermore I changed the theme to twentyseventeen and I added "cred_form_validate" to functions.php instead of using the Code Snippets plugin. It still runs twice.
Nigel is on vacation. This is Minesh here and I'll take carer of this ticket and try to help you further. Hope this is OK.
Well - I need problem URL and access details to check why the hook cred_form_validate run two time.
Please let me know where exactly you added the hook: cred_form_validate
*** 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 would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).
I have set the next reply to private which means only you and I have access to it.
I can duplicate the same problem, and it is a known problem, it has already been put in our to-do list, our developers are working on it, I will update this thread if there is anything news.