Required fields for event submission form: Code doesn't work anymore

Home Forums Calendar Products Community Events Required fields for event submission form: Code doesn't work anymore

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1330863
    Oliver
    Participant

    Hi,

    after one of the latest releases (probably the one which completely changed the event submission form) the code that is offered here to

    a) add required fields
    https://theeventscalendar.com/knowledgebase/required-fields-for-events-submission-form/

    and

    b) custom errors
    https://theeventscalendar.com/knowledgebase/required-fields-for-events-submission-form/?source=tri.be&q=/change-required-fields-on-community-event-submission-page/#errors

    doesn’t work anymore.

    Any idea why? Have the filters used above
    – add_filter( ‘tribe_events_community_required_fields’, ‘my_community_required_fields’, 10, 1 );
    – add_filter( ‘tribe_community_events_form_errors’, ‘ce_custom_error_msg’ );
    maybe removed?

    Best regards,
    Oliver

    • This topic was modified 6 years, 8 months ago by Oliver.
    #1331928
    Victor
    Keymaster

    Hi Oliver!

    Thanks for getting in touch with us!

    I’m sorry to hear those code snippets are not working for you.

    I know there were some issues regarding those required fields in the past, but they were solved. Could you please share with me the code snippets you are using so I can make some tests on my own local installation and see if it works?

    Thanks,
    Victor

    #1331995
    Oliver
    Participant

    Hi Victor,

    here is the code I’m using. I’m using it untouched for a long time – maybe >1 year.
    Would be great I you have an idea 🙂

    
    //-----------------------------------------------------------------------------------
    // Make additional fields required in Community events submission page
    // https://theeventscalendar.com/knowledgebase/required-fields-for-events-submission-form/
    //-----------------------------------------------------------------------------------
    
    function my_community_required_fields( $fields ) 
    {
    
        if ( ! empty($_FILES['event_image']['name']) )
    	{
        	$fields = array(
            'post_title',
            'post_content',
            'EventStartDate',
            'venue',
            '_ecp_custom_1',
            '_ecp_custom_3'
        	);
        }
        else if ( ! empty( $_POST['_ecp_custom_1']) )
        {
        	$fields = array(
            'post_title',
            'post_content',
            'EventStartDate',
            'venue',
            'event_image',
            '_ecp_custom_3'
        	);    
        }
        else {
        	$fields = array(
            'post_title',
            'post_content',
            'EventStartDate',
            'venue',
            '_ecp_custom_3'
        	);    
        }
    
        
        return $fields;
    }
    add_filter( 'tribe_events_community_required_fields', 'my_community_required_fields', 10, 1 );
    
    //-----------------------------------------------------------------------------------
    // Check, it not allowed characters have been entered in the cost. Allowed are: A-z, 0-9
    // https://theeventscalendar.com/knowledgebase/required-fields-for-events-submission-form/?source=tri.be&q=/change-required-fields-on-community-event-submission-page/#errors
    //-----------------------------------------------------------------------------------
    
    function ce_custom_error_msg( $errors ) 
    {
        $cost = trim( $_POST['EventCost'] );
        
        if ( empty( $cost ) ) {
            return false;
        }
        
        if ( preg_match( "/^[a-zA-Z0-9,. \s]+$/", $cost ) ) {
            return $errors;
        }
        $existing_errors = '';
        $type = 'error';
        if ( is_array( $errors ) ) {
            $existing_errors = $errors[0]['message'];
            $type = $errors[0]['type'];
        }
        $errors[0] = array(
            'type' => $type,
            'message' => 'Unerlaubte Zeichen im Eintrittsfeld! Bitte geben Sie den Eintrittspreis z.B. wie folgt ein:<li>26</li><li>26-30</li><li>Spende</li>Ergänzen Sie weitere Infos bitte bei der Beschreibung der Veranstaltung!' . $existing_errors
        );
    	
        return $errors;
    }
    
    add_filter( 'tribe_community_events_form_errors', 'ce_custom_error_msg' );
    

    Best regards,
    Oliver

    #1332621
    Victor
    Keymaster

    Hi Oliver!

    Thanks for coming back with the code.

    Despite throwing a PHP warning, I could make the required fields work on my local installation.

    Just to confirm, are you not able to get any of the required fields to work, or just some of them?

    In addition, are you making any template customization for the community add form? If so, let us know about it.

    Thanks,
    Victor

    #1333002
    Oliver
    Participant

    This reply is private.

    #1333266
    Victor
    Keymaster

    This reply is private.

    #1333312
    Oliver
    Participant

    Wow, now it works! 🙂

    But where is the difference in the code? I can’t see any!

    Best regards,
    Oliver

    #1333436
    Victor
    Keymaster

    Hey Oliver!

    Glad it worked out for you! 🙂

    The difference was inside the ce_custom_error_msg() function. You were returning false when cost was empty, thus not returning all other error messages.

    Is there anything else I can help you with? Let me know.

    Best,
    Victor

    #1333592
    Oliver
    Participant

    Oh, that was too simple 😉

    Thanks for finding it!!! Best man!!

    Best regards,
    Oliver

    #1333638
    Victor
    Keymaster

    I’m happy to help Oliver 🙂

    I’ll close this now, but feel free to open a new topic if anything comes up.

    Cheers!
    Victor

Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘Required fields for event submission form: Code doesn't work anymore’ is closed to new replies.