Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Barry

    (@barryhughes-1)

    Hi there!

    I don’t see why not. To actually add the new fields there are a couple of routes. One is to set up an action on the following hook:

    eventrocket_rsvp_anon_submission_form

    The other is to copy and override the RSVP form and customize it to suit your needs. The original can be found in:

    event-rocket/templates/rsvp-form.php

    Simply copy it to your theme as follows:

    themes/YOUR_THEME/tribe-events/rsvp-form.php

    Then modify away. To actually process the submitted data, you could make use of the following (filter) hook:

    eventrocket_rsvp_accept_anon_submission

    By setting your own filter to run on a higher-than-default priority, you can test to see if the RSVP system is accepting the submission and A) change this decision if the new fields have been left blank, etc B) take this as an opportunity to store the extra data.

    Thread Starter treeslikeme

    (@treeslikeme)

    Thank you so much for your response!

    Is there anyway you could elaborate on the storing of data? Everything you’ve said has been extremely helpful. I’m just having trouble finishing the task of storing the name in any capacity.

    Plugin Author Barry

    (@barryhughes-1)

    Hi @treeslikeme,

    This shows the basic form:

    add_filter( 'eventrocket_rsvp_accept_anon_submission', 'rsvp_maybe_store_additional_data', 20 );
    
    function rsvp_maybe_store_additional_data( $accepted ) {
        if ( $accepted ) rsvp_store_additional_data();
        return $accepted;
    }
    
    function rsvp_store_additional_data() {
        $event_id  = get_the_ID();
        $anon_user = $_POST['eventrocket_anon_id'];
    
        update_post_meta( $event_id,
            "_RSVP_Field_{$anon_user}_Extra_Field_A",
            $_POST['some_field'] );
    
        update_post_meta( $event_id,
            "_RSVP_Field_{$anon_user}_Extra_Field_B",
            $_POST['some_other_field'] );
    }

    Important things to note:

    • I haven’t tested this code – so don’t be too surprised if an error or two pop up!
    • It’s deliberately simple and so lacks any kind of validation in relation to the form data it accepts – of course it would be sensible to take care of this

    Hope that helps ??

    Thread Starter treeslikeme

    (@treeslikeme)

    Barry-

    Again, I really appreciate you taking the time to respond!

    Your example certainly does save the information as metadata, but what I’m trying to do is save it to the actual attendees list, so instead of “ANONYMOUS ([email protected])” it would be “EXAMPLE ([email protected])”

    I see the “ANONYMOUS” portion of the attendees list is coming from the function list_anon_positives. But for the life of me, I can’t override it or affect it at all. Any suggestions?

    Thanks again for your time.

    Plugin Author Barry

    (@barryhughes-1)

    Hi @treeslikeme,

    You can change what is displayed for each entry in that list and, for anonymous RSVPs, the hook in question is:

    eventrocket_anon_attendee_entry

    Here’s a minimal example that does nothing as is, but should show the basic form:

    function rsvp_include_custom_anon_data( $attendee_entry ) {
        // Work your magic in here!
        // - Strip out the identifier (email address) for the user
        // - Match it up with the stored meta data for the event
        // - Form your customized string for the attendee list
        // - Don't forget to return the new/modified string!
        return $attendee_entry;
    }
    
    add_filter( 'eventrocket_anon_attendee_entry', 'rsvp_include_custom_anon_data' );
    Thread Starter treeslikeme

    (@treeslikeme)

    That’s great! Thank you so much.

    Is there any way to actually get the post ID from here, though?

    I need the post ID to query the metadata.

    get_the_ID() and global $post; $post->ID; are not working from within this function.

    Plugin Author Barry

    (@barryhughes-1)

    Try:

    $post_id = absint( $_POST['event_id'] );

    Thread Starter treeslikeme

    (@treeslikeme)

    You have been so helpful! I couldn’t have done it without you. Thanks for the tremendous support.

    In case anyone ever needs this, here’s my code. It’s a little rough perhaps, but it works:

    in rsvp-form.php:

    <input type="text" name="eventrocket_anon_name" id="eventrocket_anon_name" value="" placeholder="<?php esc_attr_e( 'Your Name', 'eventrocket' ) ?>" />
    <input type="text" name="eventrocket_anon_id" id="eventrocket_anon_id" value="" placeholder="<?php esc_attr_e( '[email protected]', 'eventrocket' ) ?>" />
    <button class="eventrocket rsvp anon attend" name="rsvp_attend" value="__anon">
    <?php _ex( 'Yes! I will attend', 'anon attendance button', 'eventrocket' ) ?>
    </button>

    In functions.php:

    add_filter( 'eventrocket_rsvp_accept_anon_submission', 'rsvp_maybe_store_additional_data', 20 );
    
    function rsvp_maybe_store_additional_data( $accepted ) {
        if ( $accepted ) rsvp_store_additional_data();
        return $accepted;
    }
    
    //On RSVP Action, store Name as custom field. "_RSVP_Field_email_address_com"
    function rsvp_store_additional_data() {
        $event_id  = get_the_ID();
        $anon_user = $_POST['eventrocket_anon_id'];
    	$anon_name = $_POST['eventrocket_anon_name'];
    	$id = str_replace("@","_",$anon_user);
    	$id = str_replace(".","_",$id);
        update_post_meta( $event_id,
            "_RSVP_Field_{$id}",
            $anon_name );
    }
    
    function rsvp_include_custom_anon_data( $string ) {
    
      //When displaying attendees...
    	foreach(preg_split('/\s/', $string) as $token) {
    		//Find the email addresses
    		$email = filter_var(filter_var($token, FILTER_SANITIZE_EMAIL), FILTER_VALIDATE_EMAIL);
    		//Reformat them as email_address_com
    		$uid = str_replace("@","_",$email);
    		$uid = str_replace(".","_",$uid);
    		//Find the Post ID
    		$post_id = absint( $_POST['event_id'] );
    		if ($email !== false) {
    			//Check for NAME metadata in post
    			$metafield = '_RSVP_Field_'.$uid;
    			$name = get_post_meta ( $post_id, $metafield, true);
    				if($name) {
    					//Include Name.
    					$emails[] = $name . ' ('.$email.')';	
    
    				} else {
                $emails[] = 'Anonymous ('.$email.')';
    				}
            }
        }
        return $emails;
    
    }
    
    add_filter( 'eventrocket_anon_attendee_entry', 'rsvp_include_custom_anon_data' );
    Plugin Author Barry

    (@barryhughes-1)

    Awesome, happy to help and thank you so much for sharing the solution (I’d definitely encourage others to similarly share examples of custom work, whether in relation to RSVPs or other aspects of the plugin) ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘RSVP Fields’ is closed to new replies.