Okay
  Public Ticket #3213062
Customize RSVP Form
Closed

Comments

  •  2
    Robin started the conversation

    Hey

    Fantastic plugin, I love it! 

    Question: Is there a way to customize the RSVP form? Add additional fields and name-fields for the amount of people indicated?

    Cheers, Robin

  •  771
    Zhivko replied

    Hi,

    It's possible to add extra fields via custom hooks.

    You can check out this article.

    https://stachethemes.ticksy.com/article/16037/


    Stachethemes Developer

  •  2
    Robin replied

    Excellent, thanks for this. But the additional fields cannot be integrated in the RSVP notification mail though, the fields are not shown when I add them to the RSVP template. How can that be done?

  •  771
    Zhivko replied

    Could you elaborate what you want to achieve?

    It's possible to register extra special {{words}} for the template but I'll need to know for which email template are you talking about.


    Stachethemes Developer

  •  2
    Robin replied

    I'd like add additional fields in the RSVP form. That worked well with the code you've provided. Now, when I try to implement the new fields in the RSVP-Mail-Template (the one that is editable behind the text "Notify author when new attendee has been added via RSVP"), then it won't appear in the mail.

    It looks like this:

    Registration for {{title}} on {{attend_date}} 
    Attendee: {{attendee}} 
    Additional Field
    : {{addfield}} 

    The Mail I get looks like this:

    Registration for Compliance Presentation on 2023-04-17
    Attendee: Robin Heizmann
    Additional Field: {{addfield}} 

  •  771
    Zhivko replied

    You can use this hook to register {{addfield}} placeholder.

    add_filter('stec_send_event_author_new_attendee', function ($data, $event, $attendee) {
     
        // adds {{addfield}} special word
        add_filter('stec_mail_add_special_words', function ($filter) use ($attendee) {
            $filter['replace'][] = '{{addfield}}'; // the special word placeholder 
            $filter['with'][]    = $attendee->get_custom_data('addfield'); // meta key 
            return $filter;
            
        }, 10);
        
        return $data;
    }, 10, 3);

    Usually this code is placed in the theme or child-theme functions.php file.



    Stachethemes Developer

  •  2
    Robin replied

    Excellent, that works well, thanks a lot. Last question: I'd like to have the RSVP-notification sent to multiple email-addresses, where can I register them?

  •  771
    Zhivko replied

    You could modify the mail headers via stec_wp_mail_headers filter.

    e.g.

    add_filter('stec_wp_mail_headers', function() {
        $headers   = [];
        $headers[] = 'Cc: [email protected]';
        $headers[] = 'Cc: [email protected]';
        
        return $headers;
    });
    



    Stachethemes Developer

  •  2
    Robin replied

    Ah thanks, and how can I make the additional fields mandatory?

  •  771
    Zhivko replied

    Add required="required" attribute to the input field:

    2130063159.png



    Stachethemes Developer

  •  2
    Robin replied

    Excellent, thank you!

  •  2
    Robin replied

    Follow-Up question: When a required field is not filled out, the form cannot be sent. So far so good, but it doesn't show a "required field"-notification. Where can that be implemented/forced?

  •  771
    Zhivko replied

    I will add better alerts for the required fields in the coming days.

    Meanwhile you could use this hook:

    add_action('wp_footer', function () {
        ?>
        <script type="text/javascript">
            (function($) {             $(function() {                 if (typeof window.StecRsvpToEvent === 'undefined') {
                        return;
                    }                 var helper = new window.StecHelper();                 window.StecRsvpToEvent.prototype.popFieldsValid = function() {                     var valid = true;                     if ($('.stec-rsvp-popup-wrapper-settings input[name="name"]').val().trim() === '') {
                            valid = false;
                        }                     if ($('.stec-rsvp-popup-wrapper-settings input[type="email"]').val().trim() === '') {
                            valid = false;
                        }                     $('.stec-rsvp-popup-wrapper-settings').find('input, select').filter('[required]:visible').each(function() {                         if ($(this).is(':checkbox') && false === $(this).prop('checked')) {
                                valid = false;
                                return false;
                            } else {
                                if ('' === $(this).val().trim()) {
                                    valid = false;
                                    return false; // break;
                                }
                            }
                        });                     if (false === valid) {
                            helper.toast('Please fill all required fields', false, false, {
                                background: '#fd5c63'
                            });
                        }                     return valid;
                    }             });         })(window.jQuery);
        </script>
    <?php });

    It overrides the default verification method and shows a toast when required fields are missing.


    Stachethemes Developer

  •  2
    Robin replied

    That works perfectly well, thanks a lot!

  •  2
    Robin replied

    Hi again

    The problem just popped up again: the custom fields in the RSVP-form are not sent by mail. The code you've provided does not work anymore, the fields are blank in the mail:

    add_filter('stec_send_event_author_new_attendee', function ($data, $event, $attendee) {     // adds {{addfield}} special word    add_filter('stec_mail_add_special_words', function ($filter) use ($attendee) {        $filter['replace'][] = '{{addfield}}'; // the special word placeholder         $filter['with'][]    = $attendee->get_custom_data('addfield'); // meta key         return $filter;            }, 10);        return $data;
    }, 10, 3);

    Any ideas how to make it work again?

    Thanks, Robin