Home › Forums › Calendar Products › Community Events › Required Fields Error Messages
- This topic has 5 replies, 2 voices, and was last updated 10 years, 5 months ago by
Brian.
-
AuthorPosts
-
October 29, 2015 at 12:59 pm #1020013
Sean
ParticipantHi. 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; }October 29, 2015 at 4:35 pm #1020096Brian
MemberHi,
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
October 29, 2015 at 5:45 pm #1020109Sean
ParticipantHi 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,
KarlyOctober 30, 2015 at 5:09 am #1020189Brian
MemberHi,
Yeah the Organizer area is on my list to update.
I did help another customer with this coding on that:
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
October 30, 2015 at 6:46 am #1020201Sean
ParticipantBrian,
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,
KarlyOctober 30, 2015 at 11:21 am #1020348Brian
MemberSounds 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
-
AuthorPosts
- The topic ‘Required Fields Error Messages’ is closed to new replies.
