How to stop bots from submitting the Confirm RSVP form
-
Is there a way to prevent bots from filling out my RSVP form?
I’ve turned on recaptcha for Contact Forms, but there doesn’t appear to be a way to add recaptcha to the RSVP form.
- This topic was modified 4 years, 2 months ago by Stephen Wick.
-
Hi @swick4556,
Thanks for writing to us.
There isn’t an out-of-the-box solution available enabling you to add reCAPTCHA for RSVPs, however, you can customize the RSVP form by following our customization guide and copying the src > views > tickets > rsvp.php file into your theme from the Event Tickets plugin.
Hope this helps.
Kind regards,
MasoodI am also interested to add a recaptcha to the RSVP Form. But all my tries failed.
@swick4556 Do you have success?
- This reply was modified 4 years, 1 month ago by smoki3.
So I was now able to add the recaptcha button to the form. But I don’t know how to set the if question if it is passed
@smoki3 I have not.
Hi Stephen,
I managed to get it working now ??
You have to edit the /src/Tribe/RSVP.php and the /src/views/v2/rsvp/form/form.php.
form.php:<?php /** * Block: RSVP * Form base * * Override this template in your own theme by creating a file at: * [your-theme]/tribe/tickets/v2/rsvp/form/form.php * * See more documentation about our Blocks Editor templating system. * * @link {INSERT_ARTICLE_LINK_HERE} * * @since 4.12.3 * @since5.0.0 Updated the input name used for submitting. * * @version5.0.0 */ $going = $this->get( 'going' ); ?> <script src='https://www.google.com/recaptcha/api.js'></script> <form name="tribe-tickets-rsvp-form" data-rsvp-id="<?php echo esc_attr( $rsvp->ID ); ?>" > <input type="hidden" name="tribe_tickets[<?php echo esc_attr( absint( $rsvp->ID ) ); ?>][ticket_id]" value="<?php echo esc_attr( absint( $rsvp->ID ) ); ?>"> <input type="hidden" name="tribe_tickets[<?php echo esc_attr( absint( $rsvp->ID ) ); ?>][attendees][0][order_status]" value="<?php echo esc_attr( $going ); ?>"> <input type="hidden" name="tribe_tickets[<?php echo esc_attr( absint( $rsvp->ID ) ); ?>][attendees][0][optout]" value="1"> <div class="tribe-tickets__rsvp-form-wrapper"> <?php $this->template( 'v2/rsvp/form/title', [ 'rsvp' => $rsvp, 'going' => $going ] ); ?> <div class="tribe-tickets__rsvp-form-content tribe-tickets__form"> <?php $this->template( 'v2/rsvp/form/fields', [ 'rsvp' => $rsvp, 'going' => $going ] ); ?> <div class="g-recaptcha" data-sitekey="YOUR_SITE_KEY"></div> </div> <?php $this->template( 'v2/rsvp/form/buttons', [ 'rsvp' => $rsvp, 'going' => $going ] ); ?> </div> </form>
RSVP.php
public function generate_tickets( $post_id = null, $redirect = true ) { $secretkey = 'YOUR_SECRET_KEY'; $antwortJSON = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secretkey.'&response='.$_POST['g-recaptcha-response']); $antwortDaten = json_decode($antwortJSON); if($antwortDaten->success){ //Captcha erfolgreich gel?st $has_tickets = false; if ( null === $post_id ) { $post_id = get_the_ID(); } /** * RSVP specific action fired just before a RSVP-driven attendee tickets for an order are generated * * @param $data $_POST Parameters comes from RSVP Form */ do_action( 'tribe_tickets_rsvp_before_order_processing', $_POST ); // Parse the details submitted for the RSVP $attendee_details = $this->parse_attendee_details(); // If there are details missing, we return to the event page with the rsvp_error if ( false === $attendee_details ) { if ( $redirect ) { $url = get_permalink(); $url = add_query_arg( 'rsvp_error', 1, $url ); wp_redirect( esc_url_raw( $url ) ); tribe_exit(); } return false; } $product_ids = []; if ( isset( $_POST['tribe_tickets'] ) ) { $product_ids = wp_list_pluck( $_POST['tribe_tickets'], 'ticket_id' ); } elseif ( isset( $_POST['product_id'] ) ) { $product_ids = (array) $_POST['product_id']; } $product_ids = array_map( 'absint', $product_ids ); $product_ids = array_filter( $product_ids ); $attendee_ids = []; // Iterate over each product foreach ( $product_ids as $product_id ) { $ticket_qty = $this->parse_ticket_quantity( $product_id ); if ( 0 === $ticket_qty ) { // If there were no RSVP tickets for the product added to the cart, continue. continue; } $tickets_generated = $this->generate_tickets_for( $product_id, $ticket_qty, $attendee_details, $redirect ); if ( $tickets_generated ) { if ( is_array( $tickets_generated ) ) { $attendee_ids[] = $tickets_generated; } $has_tickets = true; } } if ( ! empty( $attendee_ids ) ) { $attendee_ids = array_merge( ...$attendee_ids ); } $order_id = $attendee_details['order_id']; $attendee_order_status = $attendee_details['order_status']; /** * Fires when an RSVP attendee tickets have been generated. * * @param int $order_id ID of the RSVP order * @param int $post_id ID of the post the order was placed for * @param string $attendee_order_status status if the user indicated they will attend */ do_action( 'event_tickets_rsvp_tickets_generated', $order_id, $post_id, $attendee_order_status ); /** @var Tribe__Tickets__Status__Manager $status_mgr */ $status_mgr = tribe( 'tickets.status' ); $send_mail_stati = $status_mgr->get_statuses_by_action( 'attendee_dispatch', 'rsvp' ); /** * Filters whether a confirmation email should be sent or not for RSVP tickets. * * This applies to attendance and non attendance emails. * * @param bool $send_mail Defaults to <code>true</code>. */ $send_mail = apply_filters( 'tribe_tickets_rsvp_send_mail', true ); if ( $send_mail ) { /** * Filters the attendee order stati that should trigger an attendance confirmation. * * Any attendee order status not listed here will trigger a non attendance email. * * @param array $send_mail_stati An array of default stati triggering an attendance email. * @param int $order_id ID of the RSVP order * @param int $post_id ID of the post the order was placed for * @param string $attendee_order_status status if the user indicated they will attend */ $send_mail_stati = apply_filters( 'tribe_tickets_rsvp_send_mail_stati', $send_mail_stati, $order_id, $post_id, $attendee_order_status ); // No point sending tickets if their current intention is not to attend if ( $has_tickets && in_array( $attendee_order_status, $send_mail_stati, true ) ) { $this->send_tickets_email( $order_id, $post_id ); } elseif ( $has_tickets ) { $this->send_non_attendance_confirmation( $order_id, $post_id ); } } // Redirect to the same page to prevent double purchase on refresh if ( $redirect && ! empty( $post_id ) ) { $url = get_permalink( $post_id ); $url = add_query_arg( 'rsvp_sent', 1, $url ); wp_redirect( esc_url_raw( $url ) ); tribe_exit(); } return $attendee_ids; } else { if ( $redirect ) { $url = get_permalink(); $url = add_query_arg( 'rsvp_error', 1, $url ); wp_redirect( esc_url_raw( $url ) ); tribe_exit(); } return false; } }
Nice job! I’ll try it out and let you know if it works for me.
Hi Stephen!
Did the solution provided work for you?
Is there anything else we can help you with?
Thanks, have a nice day!
It did not work for me.
I have Event Tickets v5.0.1.
Changing /src/views/v2/rsvp/form/form.php did not do anything for me for some reason. I could not see the changes when viewing source in the browser.
I had to change plugins/event-tickets/src/views/tickets/rsvp.php, which I copied to themes/{my_theme}/tribe-events/tickets/rsvp.php before editing.
Unfortunately, after adding the class g-recaptcha, and the data-sitekey, data-callback=”submitRSVP” and data-action=”submit” to the submit button with class tribe-button–rsvp, the inline form validation stopped working, and although I saw g-recaptcha-response in the POST to wordpress, the function, generate_tickets() in src/Tribe/RSVP.php was not being called anymore for some reason.
Thanks for your help though. You got me started. I’ll keep digging.
I got it working. I’ll post what I did soon.
- The topic ‘How to stop bots from submitting the Confirm RSVP form’ is closed to new replies.