When I create a ticket with a minimum and maximum quantity, it used to ask each additional attendee their First Name, Last Name, and Email address in the registration page.
These fields are only contained for the primary registrant now. How do I re-enable personal questions for additional attendees?
Next, eventually, I’ll need to set up custom validation for the additional attendees (check wp_users for matching First and Last name records) and also apply custom validation for other custom fields (i.e. ensure ‘Group Name’ field does not contain special characters [!&$#*].
How can I get personal questions for additional attendees back, and how would I add custom validation rules for custom fields?
Ok, it looks like a cohort of mine somehow renamed the question category ‘Personal Questions’ to a different string of text. I think I can move forward from this issue now. The custom validation question is not resolved yet.
I cannot seem to locate event-espresso/scripts/validation.js. It looks like the event espresso folder is now ‘event-espresso-core-reg’, can you comment on where the validation.js is?
function EE_validation($spco, $data){
error_log(print_r($data,true));}
add_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end','EE_validation',10,3);
It looks like $data contains the registration fields. How can I perform validation on First Name and then prevent the registration from proceeding if is invalid (i.e. numeric, for example)?
Next, eventually, I’ll need to set up custom validation for the additional attendees (check wp_users for matching First and Last name records)
Something similar already happens with the WP User integration add-on, only it uses the email address passed for each registrant. If you are looking to do more than that I’d recommend checking out how the add-on does the above, it’s in:
Which hooks into FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process
(Which also happens to be where you’ll need to hook in for any additional validation you want to do, so learning how the about methos works will be of benefit either way)
Based on the topic above, is the idea to use JQuery in a custom plugin for validation when the end user clicks ‘submit’ on the registration page?
My validation will require comparing user input values with values in the wp database. Would this be easier to achieve in PHP?
Yes, it will be easier using PHP if you need values from the database and you can use the hook I mentioned above.
I cannot seem to locate event-espresso/scripts/validation.js. It looks like the event espresso folder is now ‘event-espresso-core-reg’, can you comment on where the validation.js is?
May I ask where you are getting the above from? Thats from EE3 and does not apply to EE4, the thread you linked gives a good example of how to add js validation to EE4.
It looks like $data contains the registration fields. How can I perform validation on First Name and then prevent the registration from proceeding if is invalid (i.e. numeric, for example)?
Use the other hook I mentioned above and work from there.
AHEE__EE_Single_Page_Checkout__process_attendee_information__end first at the END of processing the attendee information step, you want to stop the process before then.
I’ve fallen a step back for reasons likely stemming from my lack of familiarity with OOP, but it’s been a progressive learning experience. I used the new hook you suggested FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process but I can no longer access/echo the registration questions via $data anymore.
Can you provide guidance for me to re-tap into Attendee Information form data? As a check. I tried to simply EED_WP_Users_SPCO::verify_user_access(); during the filter hook you recommended and it returns ‘This transaction cannot be processed. Please refresh and try again.’. How come this happens?
As another check, I’ve tried echoing each of the variables inside verify_user_access during the recommended hook: `$stop_processing,
$att_nmbr,
EE_Registration $spco_registration,
$registrations,
$valid_data, $spco`
Using `EE_Error::add_error(sprintf(
_n(
‘The payment notification generation failed.’,
‘PRINT VAR’ . $registration, /*example*/
$count_failed,
‘event_espresso’
),
$count_failed
),
__FILE__,
__FUNCTION__,
__LINE__
);`
They all yield PRINT VAR without anything else appended indicating that there’s a variable (array,object,string). Have I gone completely off the rails Tony?
I used the new hook you suggested FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process but I can no longer access/echo the registration questions via $data anymore.
Yeah, you won’t be able to just echo out the contents on the current page because the above runs on an ajax request.
You’ll need to log the details rather than output them, then view the log. Or capture the ajax request and see what is output on that.
Open Chrome dev tools, go to the Network tab and then click the submit button on checkout, you’ll see an admin-ajax.php request, view that.
As a check. I tried to simply EED_WP_Users_SPCO::verify_user_access(); during the filter hook you recommended and it returns ‘This transaction cannot be processed. Please refresh and try again.’. How come this happens?
What exactly did you try? EED_WP_Users_SPCO::verify_user_access(); isn’t going to work as your not passing any of the request variables to the method but there may be some other error, check your error logs to confirm.
Have I gone completely off the rails Tony?
Possibly, although I can’t tell from the code you provided as it makes no sense out of context 🙂
Does this thread provide clues to the solution I seek?
Not as far as I can tell.
—
Again I recommend you go back to the verify_user_access method and step through how it works, not how to call it, but what it is doing and how it stops the registration process. That method already shows you how to do most of what you are tyring to do, is using different fields but it’s all there.
You may need to contact a developer familiar with OOP to help with this.
Thanks for your tip to check admin-ajax.php, because of that I was able to increase my efficiency by at least 30%! My eyeballs feel fantastic!
—
My understanding is that I need to return true / false in the hooked function in order to stop or continue with the registration
—
Can you comment on how it is determined what variables are available when one hooks into a filter/action with a function? My original theory was, whatever arguments are passed onto apply_filters('plugin_hook',false, $arg1, $arg2) are available for use in custom functions. Upon, checking admin-ajax.php after doing print_r on the variables from apply_filters, they seem very different that $registration examples I’ve seen elsewhere. In other threads, people were able to access methods in $registration like $registration->ID(), but when I do it using the suggested hook, it returns a fatal error. Why are/Are there like 5 different $registrations? How might one trace back down to what is available for use in a given hook?
Through sheer random brute force, I happened to try printing $item to admin-ajax.php. To my amazement, it contained the submitted registration form data, including the fields I need to custom validate. This is a gigantic leap forward. How could I have discovered that $item was available before? For learning purposes, what other variable/method could I have used to access the data contained in $item?
The short answer is you look in the code to view where the hook is applied and view the variables passed to the hook.
So in the case of FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process you’d search the EE4 core codebase for the above and eventually find:
The first value is the value being filtered (in this case a flag for whether or not to stop processing), the others are additional variables you can use. So this:
My original theory was, whatever arguments are passed onto apply_filters(‘plugin_hook’,false, $arg1, $arg2) are available for use in custom functions.
Is correct.
Upon, checking admin-ajax.php after doing print_r on the variables from apply_filters, they seem very different that $registration
This doesn’t really mean anything to me as the function your hooking in with could call any variable whatever if wants….
I’ve seen elsewhere. In other threads, people were able to access methods in $registration like $registration->ID(), but when I do it using the suggested hook, it returns a fatal error.
If they have a valid EE_Registration object, then sure, that would work, but again your custom function could be doing anything, so that really doesn’t mean much. You’ll need to give clearer examples of the code your running and what it returns as without context I really can’t give you any information.
Why are/Are there like 5 different $registrations?
This is another example of a question I can’t answer without context, I have no idea where you are getting 5 registrations from, nor where EE is apparently pulling them from, without the context of the code.
Through sheer random brute force, I happened to try printing $item to admin-ajax.php. To my amazement, it contained the submitted registration form data, including the fields I need to custom validate.
??? What is $item?
Add the code you used for this to a gist or pastebin and I’ll take a look, however note that generally we (EE Support) will not provide support for customizations. I’ll take a look over and see if I can help point you in the right direction but note that the answer may well be to contact a developer familiar with WP and OOP for further help.
How could I have discovered that $item was available before?
Take a look over the link I provided for how to use hooks, it explains this in detail.
For learning purposes, what other variable/method could I have used to access the data contained in $item?
This needs more context, I have no idea what $item is here.
After entering first name, last name, email, custom questions for each attendee, and clicking “Proceed to Finalize Registrations”, admin-ajax.php shows a multidimensional array containing each attendee’s answers for all the questions ($item).
On the front end, an error message is returned (since I return true in the custom function).
the array $item wasn’t in apply_filters for the hook, but it contains all the form data submitted and I personally did not create the variable $item. Where does $item come from? How can I determine all the variables (such as $item or $data) available for use for a particular hook?
$item also doesn’t appear explicitly in the function process_registrations($registrations, $valid_data). So does it mean $item is available at any hook after FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process in the registration process?
Pardon the bombardment of posts(how can I delete old posts?). On some more experimenting, it looks like whatever variable I use in my custom function at the 5th position will always contain the multidimensional array containing registration answers. Is this accurate? Can we conclude that in
if (apply_filters(
'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process',
false,
$att_nmbr,
$registration,
$registrations,
$valid_data,
$this
$this is the 5th argument, and contains the answers in the current instance of registration, so whatever variable I name in the 5th argument of a custom function ($data, $item etc) will always refer to $this?
I was completely stumped before because I tried to explicitly use $this in function `extra_validation($att_nmbr,
$registration,
$registrations,
$valid_data,
$this)` and it kept returning an error for using $this.
the array $item wasn’t in apply_filters for the hook, but it contains all the form data submitted and I personally did not create the variable $item.
Yes, you did.
You created it in in your own callback function that is hooking in.
The variable names you use mean very little (although the should make logical sense with the data passed to them), but the order of your arguments matter, a lot.
Where does $item come from?
Here:
function extra_validation( $registration, $registrations, $valid_data, $att_nmbr, $item)
You’re callback is using the parameters passed on the hook, but it is using them incorrectly. The variable names are your own, you can call them whatever you want but the order matters, as that is how the hook passes the data over to your function. So with your above function, you are hooking into the filter and its passing data over to your function:
apply_filters(
'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process',
false, // You set this into $registration
$att_nmbr, // This into $registration
$registration, // This is $valid_data.
$registrations, // $att_nmber
$valid_data, // $item
$this // not used
)
So in your function, $valid_data from the hook is passed into $item.
You create $item, with a local scope to your function.
The above is why I couldn’t answer your questions previously as it makes no sense outside of your own callback function. $item could have been anything at all in the arguments passed above.
The short answer is to change your callback function to pass the data correctly so you can use it:
That will output exactly the same as what you had before, but now you have all of the data passed to your callback in variables that match/make sense with what the hook is passing.
How can I determine all the variables (such as $item or $data) available for use for a particular hook?
I explained that in my previous post, if you need additional details you’ll need to work through the link I provided to understand hooks.
Working with WordPress (and Event Espresso) revolves around hooks, if you don’t understand the fundamentals of how they work you’ll struggle with each and every piece of code you write for either.
here’s the output from admin-ajax.php, it contains the registration data:
Yeah, your setting whatever is in $valid_data to $item then outputting that to the browser.
$this is the 5th argument, and contains the answers in the current instance of registration, so whatever variable I name in the 5th argument of a custom function ($data, $item etc) will always refer to $this?
It’s the 6th argument, your forgetting the filtered value is the first (in this case false)
$this references the current object, you can not use that outside of a class as you are not within the current object which is why you’re getting an error.
You can reference the obect when in a variable to call methods on it, but you cannot use $this outside of a class.
so whatever variable I name in the 5th argument of a custom function ($data, $item etc) will always refer to $this?
When referencing the 6th argument (which is passed as $this and you name whatever you want, in my code above it’s $att_reg_step) then it will refer to the current object at that point, whatever variable name you give it will be used as a pointer.
It was through sheer luck and happenstance I was able to write hooked functions in the past with a clearly rudimentary understanding of how they work. Thanks Tony
I do highly recommend going over the link I provided above, hooks seem a little strange at first but they are relatively simple and once you get your head around them it all becomes much easier to work with.
Viewing 19 reply threads
The support post ‘Personal Questions for Additional Attendees no longer appear (post update)’ 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.
Support forum for Event Espresso 3 and Event Espresso 4.