Support

Home Forums Event Espresso Premium Registration form custom question type

Registration form custom question type

Posted: April 7, 2016 at 7:57 am


additout

April 7, 2016 at 7:57 am

Hi,

I recently bought EE4 plugin with EE4 Everything License for a client development.

I tried to add one custom question type without success. I’ve followed this gist snippet: https://gist.github.com/joshfeck/4b2e36b8201173750f78

The filter looks ok but does nothing. Hardcoding the core works but I wanna avoid that at all costs, of course.

Can someone point me in the right direction to accomplish this?

Thanks in advance


additout

April 7, 2016 at 8:10 am

Hi again,

I just wanna point that the snippet was in a file named functions_ee.php included in functions.php with require_once.

Once I put the snippet in functions.php file, worked.


Josh

  • Support Staff

April 7, 2016 at 8:39 am

Hi there,

We generally recommend adding custom code snippets to a functions plugin or into your WordPress theme’s functions.php file. This helps ensure the code gets loaded at the right time (i.e. not too early and not too late).


additout

April 12, 2016 at 8:17 am

Hi again,

I would like to ask something very related to the original question.

I have added one custom question type (session_checkbox) which should act like a checkbox. To try to acomplish this I have added this piece of code to functions.php


function ee_add_question_type_as_options( $question_types )
{
    $question_types[ 'session_checkbox' ] = __( 'Session Checkbox', 'ee_event_espresso' );
    return $question_types;
}

add_filter( 'FHEE__EEM_Question__construct__allowed_question_types', 'ee_add_question_type_as_options' );
function ee_generate_question( $input, $question_type, $question_obj, $options )
{
    if (!$input && $question_type == 'session_checkbox') {
        //must return an EE_Form_Input_Base child object, see event-espresso-core/libraries/form_sections/inputs. If they want to create a different class it needs to extend EE_Form_Input_Base and get autoloaded via EEH_Autoloader
        return new EE_Checkbox_Multi_Input( $question_obj->options(), $options );
    }
}

I have dequeued the script espresso_registration_form_single and enqueued a custom version of it to add this || val === 'session_checkbox' to the line 56 to let me add multiple options like in a checkbox question type.

Everything looks ok but once saved the registration form only the first checkbox checked is saved instead all checked values. If I go to the registrations admin zone and edit the answer for my custom question type, it’s saved correctly with the multiple checkboxes.

There is something I am missing or should I do something differently?

Thanks in advance.


Josh

  • Support Staff

April 13, 2016 at 2:42 pm

For that specific filter (‘FHEE__EEM_Question__construct__allowed_question_types ‘) to work you’ll need to load your callback and callback function from a plugin. If you try to load it from the theme’s functions.php file it will be too late for the filter to take effect.


additout

April 14, 2016 at 3:57 am

Thanks Josh, that worked like a charm.

The support post ‘Registration form custom question type’ 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