Posted: September 5, 2019 at 3:24 pm
|
In my site, members have buddypress groups. When they registered for an event, I’d like a custom question to be a dropdown select box populated by all the buddypress groups that the primary user is in. Is there a hook to alter the options for custom quetions? Where is the logic for custom questions/select boxes handled? THanks! |
Hi, The logic is in the generate_form_input() method. Here’s a link to its source: You’ll find there’s a filter hook at the return which should allow for altering the options. |
|
|
Hi Josh, Thanks for the the guidance. I might be misunderstanding the proper way to do this but: I see in generate_form_input():
The method |
Normally Basically the filter hook allows you to programmatically swap in a different return value. Here are a few references that explain the basics of using filter hooks: https://wordpress.org/support/topic/fliters-vs-actions-from-a-newbe/#post-1366594 |
|
|
Thanks for those resources, they’re super informative. But, I think there are some slight object oriented differences from those examples and my end goal that I can’t wrap my head around. As a test, I tried to pass an array of hard coded strings as
This returns an error saying $this can’t be used. I’ve tried subbing it out with EE_Question::options() but that’s not working either.. Am I approaching this right? I have a feeling my foo bar key values array ain’t going to work either..is the array set to be properly inserted as select box choices? Thanks in advance. |
Hi a608237, this is a bit off topic for this thread, but I wasn’t sure how else to reach you. I’m trying to achieve the same thing you did here: Update Buddypress custom xprofile field from EE event registration form Could you please email me at bsayler@naddi.org to discuss? Thanks, you’d be a lifesaver! |
|
The pseudo-variable https://www.php.net/manual/en/language.oop5.basic.php#example-172 Note that the hook you are using is passed multiple variables, this is how its called in EE:
Meaning any functions you hook into that filter have access to those if you set the hook up correctly, for example:
However, none of what you are currently using will work, not only due to the use of Then it appears what you are trying to do is return just the values you assigned earlier, but at that point, EE is expecting a form input, not a list of option values. You could have generated an input and set the option values, then returned the input at that point but not just the values themselves. I also think you’re going to run into further issues with what you are trying to do as anywhere that tries to pull in the values in the ‘standard’ way for that question is going to fail, you won’t have the relationships with question options and so on so you’re likely going to add code for this to work. I’d recommend contacting a developer familiar with OOP and/or Event Espresso as what your trying to do isn’t as simple as it may seem. |
|
|
Hi Tony, I want to give this a more serious effort before aborting. My premium status expires in 3 months so I’d like to go as far as I can while I can still get help. Can you provide a simple example function of: What is meant by the ‘standard’ way in which Event Espresso tries to pull values? |
Just to clarify, your support license does not provide support for customizations. We are often fairly relaxed with this and will help point you in the right direction when we can, but we won’t write custom code for you, thats not covered under ‘Support’.
The point of the above was intended to highlight the fact that the function is doing it wrong and returning completely the wrong values for what they filter is for. If you view where that code is applied, you can see how the inputs are generated: Just above that filter shows how EE generates the inputs for all of the different input types. I can’t really provide a better example of how EE generates the inputs than EE itself. You really need someone familiar with OOP and EE to work through this for you.
If EE generated an input, it would have ‘options’ for those inputs saved within the database. You want to completely bypass that and use your options own based on dynamic values for each user, meaning your no longer using the ‘standard’ relationships with questions and options in the DB, your using your own. Anywhere that relies on that relationship (because that is how EE questions are set up by default) may well need filtering to use your new values. |
|
The support post ‘Dynamic Select box options’ 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.