Support

Home Forums Event Espresso Premium Linking Questions to User Meta in EE4 – Autofilling Registration

Linking Questions to User Meta in EE4 – Autofilling Registration

Posted: November 17, 2015 at 4:38 am

Viewing 4 reply threads


Jeff Long

November 17, 2015 at 4:38 am

Hey there!

I found this post on autopopulating Custom Registration Fields for EE3 and wondered if I could request a similar reflection for EE4: https://eventespresso.com/topic/linking-questions-to-user-meta/

I’m mostly looking at Custom Registration Questions being autopopulated. At the simplest – can you recommend a way to hook into EE4 to manually:

  • generate a Question Group
  • generate a specific Question
  • set an answer to that specific question

Or, if there’s no problem getting IDs for questions that are created within the EE4 Registration Form editor, can you recommend a way to hook in to manually:

  • set an answer to that specific question

Thanks!


Lorenzo Orlando Caum

  • Support Staff

November 17, 2015 at 7:34 am

Hi Jeff,

Our WP User Integration offers pre-population for the personal question group. It does not currently pre-populate custom questions but there is a feature request for that.

I’ll add additional feedback to the feature request ticket.


Lorenzo


Jeff Long

November 18, 2015 at 9:58 am

Hey there,

It looks a lot to me like this is the function that’s calling the user data to the form:


	/**
	 * Added to filter that processes the return to the registration form of whether and answer to the question exists for that
	 * @param type $value
	 * @param EE_Registration $registration
	 * @param int|string $question_id in 4.8.10 and 4.8.12 it is numeric (eg 23) 
         * but in 4.8.11 it is a system ID like "email"
         * @param string $system_id passed in 4.8.12+ of EE core
	 * @return type
	 */
	public static function filter_answer_for_wpuser($value, EE_Registration $registration, $question_id, $system_id = null ) {
		//only fill for primary registrant
		if ( ! $registration->is_primary_registrant() ) {
			return $value;
		}

		if ( empty($value) ) {
			$current_user = wp_get_current_user();
                        
                        /*there was a temporary bug in EE core relating to $question_id being passed
                         * in 4.8.10 it was a question's ID (eg 23)
                         * but in 4.8.11 it was changed to a SYSTEM ID (eg 'email') 
                         * (and the new constants, like EEM_Attendee::system_question_fname, were introduced)
                         * but soon thereafter in order to fix that bug it was changed 
                         * BACK to a proper question ID (eg 23) and a new parameter was passed,
                         * $system_id
                         */
                        if( is_numeric( $question_id ) && ! defined( 'EEM_Attendee::system_question_fname' ) ) {
                            //4.8.10-style. Use the old constants
                            $firstname = EEM_Attendee::fname_question_id;
                            $lastname = EEM_Attendee::lname_question_id;
                            $email = EEM_Attendee::email_question_id;
                            $id_to_use = $question_id;
                        } elseif( ! is_numeric( $question_id ) && defined( 'EEM_Attendee::system_question_fname' ) ) {
                            //4.8.11-style. Use the new constants
                            $firstname = EEM_Attendee::system_question_fname;
                            $lastname = EEM_Attendee::system_question_lname;
                            $email = EEM_Attendee::system_question_email;
                            $id_to_use = $question_id;
                        } elseif( is_numeric( $question_id ) && defined( 'EEM_Attendee::system_question_fname' ) ) {
                            //4.8.12-style. Use the new constants and the $system_id
                            $firstname = EEM_Attendee::system_question_fname;
                            $lastname = EEM_Attendee::system_question_lname;
                            $email = EEM_Attendee::system_question_email;
                            $id_to_use = $system_id;
                        } else {
                            // ! is_numeric( $question_id ) && defined( 'EEM_Attendee::system_question_fname' )
                            //weird shouldn't ever happen. Just use the old default
                            $firstname = EEM_Attendee::fname_question_id;
                            $lastname = EEM_Attendee::lname_question_id;
                            $email = EEM_Attendee::email_question_id;
                            $id_to_use = $question_id;
                        }
                        

			if ( $current_user instanceof WP_User ) {
				switch ( $id_to_use ) {

					case $firstname :
						$value = $current_user->get( 'first_name' );
						break;

					case $lastname :
						$value = $current_user->get( 'last_name' );
						break;

					case $email :
						$value = $current_user->get( 'user_email' );
						break;

					default:
				}
			}
		}
		return $value;
	}

Is that accurate?

I’m wondering if there’s documentation on a few elements of this code.

First, and most importantly, it looks like we’re calling the users name with the following –

$firstname = EEM_Attendee::system_question_fname;

Is there a parameter available for other other slugs? Like…

$custom-question1 = EEM_attendee::custom_question_1

And importantly (for me), can I use the EEM_attendee method to “secretly” submit the field data to the user account?

EEM_attendee::custom_question_1 = $value . $value2 . $value3;

Thanks!

Also


Jeff Long

November 19, 2015 at 9:52 am

Hello! Just a bump here.

Would this sort of question be something I could have a discussion about after purchasing a support token?


Michael Nelson

  • Support Staff

November 19, 2015 at 2:37 pm

Hey jeff,
here’s a code snippet that extends our WP User integration addon so that it autopopulates the form with the user’s previous answers to custom questions: https://github.com/eventespresso/ee-code-snippet-library/blob/master/checkout/mn_wp_user_addon_save_custom_answers_too.php

Does that help much? I know it’s not exactly answering your questions, but I took a guess that this might be getting at the heart of what you’re wanting.

Viewing 4 reply threads

The support post ‘Linking Questions to User Meta in EE4 – Autofilling Registration’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso