Required Fields Error Messages

Home Forums Calendar Products Community Events Required Fields Error Messages

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1020013
    Sean
    Participant

    Hi. I had previously made note of the fact that the Required Fields for Event Submission Form guide is outdated and unfortunately has some bugs in the code offered, but wanted to share that here in case the responding rep was not aware of those issues.

    With that said, until the guide is fixed, I was hoping you could provide some guidance with how we can:
    1) Change the default error message that is returned to users when a required field is missing (for example, change “Tax Input is required” to “Event Category is required”)
    2) How we can add a Custom Error Message at the top of the page when errors are returned to the user. Would it be possible to give an example of what we should replace “$some_condition” with (if this bit of code from the afformentioned guide is still valid)?

    add_filter( 'tribe_community_events_form_errors', 'ce_custom_error_msg' );
     
    function ce_custom_error_msg( $errors ) {
        if ( ! isset( $some_condition ) ) 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' => '<h5>You did not do something critical</h5>' . $existing_errors
        );
     
        return $errors;
    }
    #1020096
    Brian
    Member

    Hi,

    Thanks for using our plugins. I can help out here.

    I know some of that guide needs to be updated for the Organizers, but was not aware the coding there did not work.

    Are you finding the coding from the guide is not working?

    Let me know and we can go from here.

    Thanks

    #1020109
    Sean
    Participant

    Hi Brian,

    I did not see any mention of how to replace an error message in the guide. Regarding the code in the guide, the section for the organizers did not work, but I was already able to get that resolved.

    I was able to find an old post which seems to have addressed my two questions here (changing a specific error message and including a custom message before the individual errors). Would you be able to give this a quick glance to ensure it doesn’t include any code that is deprecated or otherwise might conflict with version 4.0?

    // Customize Required Fields Error Message
    function ce_custom_error_msg( $errors ) {
    // Don't filter if it is an 'update' or other type of message
    if ( $errors[0]['type'] != 'error' ) return $errors;
     
    $existing_errors = '';
    $type = 'error';
     
    if ( is_array( $errors ) ) {
    $existing_errors = $errors[0]['message'];
    $type = $errors[0]['type'];
    }
     
    // Set overall message by appending a heading to the front
    $errors[0] = array(
    'type' => $type,
    'message' => '<h5>There was a problem submitting your event. The following fields are required:</h5>' . $existing_errors
    );
     
    // User str_replace to choose a specific message to change
    $errors[0]['message'] = str_replace( 'Tax Input is required', 'Event Category is required', $errors[0]['message'] );
    $errors[0]['message'] = str_replace( 'Organizer is required', 'Organizer Name is required', $errors[0]['message'] );
    $errors[0]['message'] = str_replace( 'Venue is required', 'Venue Name is required', $errors[0]['message'] );
     
    return $errors;
    }
    
    // Return custom error message 
    add_filter( 'tribe_community_events_form_errors', 'ce_redirect_after_submit', 10, 1 );
    function ce_redirect_after_submit( $messages ) {
    if ( is_array( $messages ) && !empty( $messages ) ) {
    $messages = ce_custom_error_msg( $messages );
    $first_message = reset( $messages );
    if ( $first_message['type'] == 'update' ) {
    add_action( 'parse_request', 'tribe_redirect_after_community_submission', 11, 1 );
    }
    }
    return $messages;
    }

    Thank you,
    Karly

    #1020189
    Brian
    Member

    Hi,

    Yeah the Organizer area is on my list to update.

    I did help another customer with this coding on that:

    Make organizer email required

    I looked over the coding and do not see anything that would cause an issue outright with 4.0

    I will see about including your coding and mine for the organizers in the guide and test against 4.0 to make sure it all works.

    Does that work for you? Do you have what you need now?

    Let me know and I can help out more.

    Thanks

    #1020201
    Sean
    Participant

    Brian,

    Thanks for looking at the code and glad to hear there shouldn’t be any issues with 4.0 compatibility.

    I think this is all set for now.

    Best,
    Karly

    #1020348
    Brian
    Member

    Sounds good..

    Since this is marked resolved I am going to close this ticket, but if you need anything else related to this topic or another please post a new topic on the forum and we can help you out.

    Thanks

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Required Fields Error Messages’ is closed to new replies.