Submission Form – Required Fields and Error Message

Home Forums Calendar Products Community Events Submission Form – Required Fields and Error Message

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #1393170
    Sean
    Participant

    Hi,

    We’re finally updating to the latest version of Community Events after updating our template overrides with the new functionality and views introduced earlier this year. One area we’re having trouble with is the functions to set the required fields and error message for the Community Events Submission Form.

    Following your updated article at https://theeventscalendar.com/knowledgebase/required-fields-for-events-submission-form/, we have added the following to our functions.php file:

    //Customize Event Required Fields
    add_filter( 'tribe_events_community_required_fields', 'my_community_required_fields', 10, 1 );
    
    function my_community_required_fields( $fields ) {
    
        if ( ! is_array( $fields ) ) {
            return $fields;
        }
    
        $fields[] = 'EventStartDate';
        $fields[] = 'EventStartHour';
        $fields[] = 'EventStartMinute';	
        $fields[] = 'EventURL';
    	$fields[] = 'venue';
    	$fields[] = 'organizer';
    
        return $fields;
    }
    
    //Customize Venue Required Fields
    add_filter( 'tribe_events_community_required_venue_fields', 'my_venue_community_required_fields', 10, 1 );
    
    function my_venue_community_required_fields( $fields ) {
        
        if ( ! is_array( $fields ) ) {
            return $fields;
        }
    
        $fields[] = 'Venue';
        $fields[] = 'Address';
        $fields[] = 'City';
        $fields[] = 'State';
        $fields[] = 'Zip';
    
        return $fields;
    }
    
    //Customize Organizer Required Fields
    add_filter( 'tribe_events_community_required_organizer_fields', 'my_organizer_community_required_fields', 10, 1 );
    
    function my_organizer_community_required_fields( $fields ) {
        
        if ( ! is_array( $fields ) ) {
            return $fields;
        }
    
    	$fields[] = 'Organizer';
        $fields[] = 'email';
    
        return $fields;
    } 

    With this code, we’ve encountered a few issues/bugs:
    1. The Event Description is returned as a required field, even though it is not set as required. How can we remove this as a required field?
    2. The Event Start Hour and Event Start Minute are not being recognized as having values submitted even though the time fields have values selected from the time drop down.
    3. The Event Date and Event Times submitted are not retained when an error (required field message) is returned (they reset to the default values).
    4. In addition to the specific Venue and Organizer fields being returned as “Organizer Name is required”, etc, an additional row of “Organizer is required” is also returned (see attached screenshot). Is the code at the bottom of this post still valid with the recent version of the plugins to modify the error messages? (this was crafted by Modern Tribe last year, but given the major updates to Community Events, we’re unsure if using this would lead to issues).

    Can you please advise how we can get these fixed/resolved?

    Thank you!
    Karly

    // 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
    if ( strpos($_SERVER['REQUEST_URI'], '/events/community/edit/') !== 0 ) {
    // You are not editing an event
    $errors[0] = array(
    'type' => $type,
    'message' => '<strong>There were errors with your submission.</br>
    Please review the following and resubmit your event.</br>
    *If you are uploading a logo, you will need to reselect it.</br></br></strong>' . $existing_errors
    );
    }
    
    if ( strpos($_SERVER['REQUEST_URI'], '/events/community/edit/') === 0 ) {
    // You are editing an event
    $errors[0] = array(
    'type' => $type,
    'message' => '' . $existing_errors
    );
    }
    
    // User str_replace to choose a specific message to change
    $errors[0]['message'] = str_replace( 'Event URL is required', 'Event Website URL is required', $errors[0]['message'] );
    $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 and Email are required', $errors[0]['message'] );
    $errors[0]['message'] = str_replace( 'G-recaptcha-response is required', '', $errors[0]['message'] );
    $errors[0]['message'] = str_replace( 'Venue Name is required', '', $errors[0]['message'] );
    $errors[0]['message'] = str_replace( 'Venue is required', '', $errors[0]['message'] );
    $errors[0]['message'] = str_replace( 'Organizer Name is required', '', $errors[0]['message'] );
    $errors[0]['message'] = str_replace( 'Invalid value for the Anti-Spam Check', 'Please confirm you are human by clicking the I\'m not a robot checkbox', $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;
    }
    #1393221
    Sean
    Participant

    PS – one more issue:

    5. When errors are returned, the values entered into the respective Venue and Organizer fields (Venue Name, Address, Venue Website, Organizer Email, etc) are not retained.

    #1395349
    Victor
    Keymaster

    Hi Karly!

    I’ll be happy to help you with this issue.

    I will run some tests on my end with those customizations and will come back to you to answer each of your questions.

    My apologies for the delay here as we’ve been dealing with a higher demand in our forums this last couple of days.

    Please hang in there.

    Thanks,
    Victor

    #1396240
    Sean
    Participant

    No worries Victor 🙂 Thanks for investigating these!

    #1396257
    Victor
    Keymaster

    Hi Karly!

    Thanks again for your patience. Let me go through each of your questions:

    1. The event description is required by the Community Submission form by default. If you want to not make it required, you can remove the post_content field from the required array by adding the following in the my_community_required_fields function: unset( $fields[0] );

    2. EventStartHour and EventStartMinute are not valid fields to be required. Instead, you should use the EventStartTime value to require the Start Time.

    3. Unfortunately, this is actually a bug we are already aware of. So I will link this thread to the bug report so we can let you know once a fix is released for it.

    4. This is because you are adding the organizer to the required event fields in the ‘tribe_events_community_required_fields’ filter. This means that if the user does not create a new oganizer, it will be required to select one of the available.

    Regarding the other code, I did a few tests with it and I could not find any issues about it. However, I would suggest you make a few tests with your own site (preferably in a staging/dev environment) to make sure that no conflicts arise before implementing in the live site.

    I hope that helps. Let me know if you have any follow up questions and I’ll be happy to help.

    Best,
    Victor

    #1396596
    Sean
    Participant

    Good morning Victor,

    Thanks again for your advice and solutions. I’m happy to report that I was able to get the above issues fixed with the information you provided!

    I’ll keep an eye out for a fix being released for the Date & Time bug.

    Can you please confirm if #5 above (Venue and Organizer field values not being retained when an error is returned) will also be fixed when the fix is released for the Date & Time bug?

    Lastly, the Additional Field values are not retained when an error message is returned. If that isn’t already in the above bug report, would you be able to verify and add those fields to the fix?

    Thanks,
    Karly

    #1397738
    Victor
    Keymaster

    Hi Karly!

    Thanks for following up with this. Happy to know you could solve the issues.

    I’m sorry I missed point number five. This is different from the Date & Time bug, but I could reproduce and have already logged it as well. I’m not sure they will be fixed in the same release, as it might involve additional changes in how the fix is being applied. Nevertheless, we will keep you posted for both issues.

    I have also added the additional fields not being retained issue to the bug logs. I have also linked them all together so they can hopefully be addressed at the same time as they are closely related and would be great to have them fixed in one maintenance release.

    We appreciate you taking the time to report these issues.

    Best,
    Victor

    #1397826
    Sean
    Participant

    Sounds good. Will be looking forward to that maintenance release(s). Thanks Victor!

    Best,
    Karly

    #1398550
    Victor
    Keymaster

    Sure thing Karly! 🙂

    #1454043
    Nico
    Member

    Hi there,

    Just wanted to share with you that a new maintenance release is out, including a fix for this issue.

    Find out more about this release → https://theeventscalendar.com/maintenance-release-for-the-week-of-12-feburary-2018/

    Update the plugins and let us know if the fix works for your site,
    Cheers,
    Nico

    #1455709
    Sean
    Participant

    Hi Nico,

    Thanks for the update. I tested this on a staging site confirmed that the date and additional field values are now retained upon a failed event submission. However, the following issue persists:

    Upon a failed event submission, the values entered into the respective Venue and Organizer fields (Venue Name, Venue Address, Venue Website, Organizer Name, Organizer Email, etc) are not retained. This pertains to when the user enters a “new” Venue or Organizer into the form (if a saved Venue or Organizer is selected, that selection is retained upon a failed event submission).

    Can you please confirm if a fix for this issue is still in the queue for an upcoming maintenance release? Thank you.

    #1457364
    Victor
    Keymaster

    Hi Karly!

    Thanks for following up with this.

    I can confirm we have been able to fix the data loss upon submission for the event dates and times and for the PRO additional fields in the community form.

    Unfortunately, we couldn’t fit a fix for the New Venue and Organizer Details not being retained upon failed submission, but I can confirm this is on our records to fix in a future maintenance release cycle.

    I apologise for the confusion here. Rest assured we will notify you once we ship a fix for the remaining issue.

    We appreciate you keeping us posted about this topic.

    Best,
    Victor

    #1457566
    Sean
    Participant

    Thanks for confirming Victor!

    #1458021
    Victor
    Keymaster

    Sure thing Karly! Thank you for being on top of this 🙂

    We’ll keep you posted

    #1659257
    Sky
    Keymaster

    Hi There!

    Just wanted to share with you that a new release of our plugins is out, including a fix for this issue.

    Find out more about this release → https://theeventscalendar.com/maintenance-release-for-the-week-of-11-november-2018/

    We apologize for the delay and appreciate your patience while we worked on this.

    As always, we suggest to setup a dev/staging site so you can make all plugin updates without disrupting the live site.

    Please update the plugins and let us know if the fix works for your site.

    Regards,
    Sky

Viewing 15 posts - 1 through 15 (of 16 total)
  • The topic ‘Submission Form – Required Fields and Error Message’ is closed to new replies.