Warning when Organizer Email Required snippet is used

Home Forums Calendar Products Community Events Warning when Organizer Email Required snippet is used

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1029834
    Graphic
    Participant

    Hello,

    I would like to make the organizer email required on our Community Events submission form.
    I have pasted Brian’s snippet into our child theme functions.php file, as per this thread: https://theeventscalendar.com/support/forums/topic/make-organizer-email-required/#dl_post-1007511

    Here’s what I’m using:

    add_filter( ‘tribe_events_community_required_fields’, ‘tribe_community_required_fields_org_email’, 10, 1 );
    function tribe_community_required_fields_org_email( $fields ) {

    $required_email = $_POST[‘organizer’][‘Email’];

    foreach( $required_email as $email) {
    if ( empty( $email ) )
    $fields[] = ‘Organizer Email’;
    }

    return $fields;
    }

    There is now a message on the page that says Warning: Invalid argument supplied for foreach()
    We are using the Enfold theme. I’ve posted the page link in private data.

    When I activate Twenty Fifteen or Twenty Fourteen themes, the warning message doesn’t appear, and they also don’t prompt for an organizer email if the field is left empty when submitting an event.

    The Enfold Theme however shows the warning. When an event is submitted without an organizer email, it shows an error message for the missing email field, plus adds an additional organizer section below the original one, showing two organizer sections instead of one.

    Maybe I’ve included the code incorrectly. Please let me know. Thanks

    #1029898
    Brian
    Member

    Hi,

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

    What file did you put the snippet into?

    When do you get this message?

    Warning: Invalid argument supplied for foreach()

    Does it always show? or just if you click submit.

    Thanks

    #1029910
    Graphic
    Participant

    This reply is private.

    #1030352
    Brian
    Member

    Hi,

    This is not an official feature so I am limited in supporting it and it may not work in all cases.

    I found this coding gets rid of the warnings and notices:

    add_filter( ‘tribe_events_community_required_fields’, ‘tribe_ommunity_required_fields_org_email’, 10, 1 );

    function tribe_ommunity_required_fields_org_email( $fields ) {
    if ( isset ( $_POST ) && isset( $_POST[‘organizer’] ) ) {

    $required__field_id = $_POST[‘organizer’][‘OrganizerID’];

    if ( is_array( $required__field_id ) ) {

    $i = 0;

    foreach ( $required__field_id as $organizer_id ) {

    if ( $organizer_id > 0 ) {
    $i++;
    } elseif ( empty( $_POST[‘organizer’][‘Email’][$i] ) ) {
    $fields[] = ‘Organizer Email’;
    $i++;
    }
    }

    }
    } elseif ( isset ( $_POST ) && ! isset( $_POST[‘organizer’] ) ) {
    $fields[] = ‘Organizer’;
    }

    return $fields;
    }

    It should also now account for the existing Organizers and work for them.

    Let me know how that works out.

    Thanks

    #1030420
    Graphic
    Participant

    That seems to have worked. Thanks so much!

    #1030446
    Brian
    Member

    Great, glad it helps, I am going to go ahead and close this ticket, but if you need help on this or something else please post a new ticket.

    Thanks!

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Warning when Organizer Email Required snippet is used’ is closed to new replies.