• Hello, I would like users to be able to submit events anonymously.

    How and where can I change the settings using placeholders so that, for example, the time zone is not selectable or the region, country, or URL fields are hidden for the address?

    I’ve spent about two hours searching for the settings and changing various things, but so far I haven’t succeeded.

    Thank you in advance.

Viewing 15 replies - 31 through 45 (of 49 total)
  • My guess is that you are getting the critical error because copied the code snippet from the email instead of copying it from the code block in my reply.

    Try copying it directly from this code block:

    add_filter('em_event_validate', function( $valid, $EM_Event) {
    if( !empty($EM_Event->event_owner_anonymous) ) {
    if (array_key_exists('Admission', $EM_Event->event_attributes) && EM_Event_attributes['Admission'] == "Please select") {
    $valid = false;
    $EM_Event->add_error( sprintf(__("%s must be selected.", 'events-manager'), __('An Admission type','events-manager')) );
    }
    }
    return $valid;
    }, 10, 2 );

    I suggest using the Code Snippets plugin when adding code snippets.

    I’m just an unpaid volunteer trying to help people on this forum. I am not the plugin owner. I think PHP code is necessary to make the fields required (or possibly javascript) but I don’t have time to write and test the code necessary to do what you’re asking. You can modify the html to indicate the fields are required but that will not force that the fields are actually filled in.

    Thread Starter gudrun

    (@gudrunpetz)

    Oh, sorry, I thought you were the owner.

    Then I’ll have to clarify this via HTML.

    The add-filter doesn’t work.

    Should I use Pro Support for my problems?

    I don’t know anything about the pro support forum.

    I asked DeepSeek how to make all the fields in the event form to be required and here was the answer:

    add_filter('em_event_validate', 'make_all_em_fields_required', 10, 2);

    function make_all_em_fields_required($result, $EM_Event) {
    // Event name
    if (empty($EM_Event->event_name)) {
    $EM_Event->add_error(__('Event name is required', 'events-manager'));
    $result = false;
    }

    // Event description
    if (empty($EM_Event->post_content)) {
    $EM_Event->add_error(__('Event description is required', 'events-manager'));
    $result = false;
    }

    // Location fields
    if (!empty($EM_Event->location_id)) {
    $EM_Location = $EM_Event->get_location();
    if (empty($EM_Location->location_name)) {
    $EM_Event->add_error(__('Location name is required', 'events-manager'));
    $result = false;
    }
    if (empty($EM_Location->location_address)) {
    $EM_Event->add_error(__('Location address is required', 'events-manager'));
    $result = false;
    }
    if (empty($EM_Location->location_town)) {
    $EM_Event->add_error(__('Location town/city is required', 'events-manager'));
    $result = false;
    }
    }

    // Date and time
    if (empty($EM_Event->event_start_date)) {
    $EM_Event->add_error(__('Start date is required', 'events-manager'));
    $result = false;
    }

    return $result;
    }

    To make the custom fields required:

    add_filter('em_event_validate', 'require_custom_fields', 10, 2);

    function require_custom_fields($result, $EM_Event) {
    if (empty($_REQUEST['event_attributes']['your_custom_field'])) {
    $EM_Event->add_error(__('Custom field is required', 'events-manager'));
    $result = false;
    }
    return $result;
    }

    For example if the custom field is Admission you would use the following:

    add_filter('em_event_validate', 'require_custom_fields', 10, 2);

    function require_custom_fields($result, $EM_Event) {
    if (empty($_REQUEST['event_attributes']['Admission']) || $_REQUEST['event_attributes']['Admission'] == 'Please select') {
    $EM_Event->add_error(__('Admission field is required', 'events-manager'));
    $result = false;
    }
    return $result;
    }

    In order to make all the booking fields to be required:

    add_filter('em_booking_validate', 'make_all_booking_fields_required', 10, 2);

    function make_all_booking_fields_required($result, $EM_Booking) {
    // Require first name
    if (empty($EM_Booking->booking_meta['registration']['user_name'])) {
    $EM_Booking->add_error(__('First name is required', 'events-manager'));
    $result = false;
    }

    // Require last name
    if (empty($EM_Booking->booking_meta['registration']['user_surname'])) {
    $EM_Booking->add_error(__('Last name is required', 'events-manager'));
    $result = false;
    }

    // Require email
    if (empty($EM_Booking->booking_meta['registration']['user_email'])) {
    $EM_Booking->add_error(__('Email address is required', 'events-manager'));
    $result = false;
    } elseif (!is_email($EM_Booking->booking_meta['registration']['user_email'])) {
    $EM_Booking->add_error(__('Please enter a valid email address', 'events-manager'));
    $result = false;
    }

    // Require phone
    if (empty($EM_Booking->booking_meta['registration']['dbem_phone'])) {
    $EM_Booking->add_error(__('Phone number is required', 'events-manager'));
    $result = false;
    }

    // Require spaces (at least 1 ticket)
    if ($EM_Booking->get_spaces() < 1) {
    $EM_Booking->add_error(__('Please select at least one space/ticket', 'events-manager'));
    $result = false;
    }

    return $result;
    }

    Of course all this code needs to be tested and corrections made as needed.

    Thread Starter gudrun

    (@gudrunpetz)

    Wow, thank you very much. I’ll get to work and test it.

    I still have the problem with the country.
    I don’t need it. I’ve already removed the HTML code, including the code in events/Locations.php.

    Unfortunately, when I create the form, it asks me for the country “A country is required.” The form cannot be submitted.

    Where and how can I deactivate/delete/mark the country field as not required?

    I think the following code snippet will fix the problem (by removing “location_country” from the required_fields array):

    add_action('em_location', function($EM_Location) {
    if (array_key_exists('location_country', $EM_Location->required_fields)) {
    $arr = [];
    foreach ($EM_Location->required_fields as $field) {
    if ($field != 'location_country') $arr[] = $field;
    }
    $EM_Location->required_fields = $arr;
    }
    });
    • This reply was modified 2 months, 2 weeks ago by joneiseman.
    Thread Starter gudrun

    (@gudrunpetz)

    Hello,

    The add-action field for the country worked.

    However, this function doesn’t work for the attributes.
    I get an error message saying I have to select something.

    No matter what value I select, the attribute isn’t applied, so I can’t submit the form.

    I’ve added this function.

    Do you know why I can’t submit the form? Set attributes as required fields

    add_filter(’em_event_validate’, ‘require_custom_fields’, 10, 2);
    function require_custom_fields($result, $EM_Event) {
    if (empty($_REQUEST[‘event_attributes’][‘Region’]) || $_REQUEST[‘event_attributes’][‘Region’] == ‘Please select’) {
    $EM_Event->add_error((‘Select the region of the event.’, ‘events-manager’)); $result = false; } if (empty($_REQUEST[‘event_attributes’][‘Admission’]) || $_REQUEST[‘event_attributes’][‘Admission’] == ‘Please select’) { $EM_Event->add_error((‘Please specify whether admission is required for the event.’, ‘events-manager’));
    $result = false;
    }
    return $result;
    }

    Another question about categories:
    I want to display the categories for events and I’m using Divi. What shortcode do I need to add to display the events for the requested event category?

    Here’s a corrected version of the code snippet:

    add_filter('em_event_validate', 'require_custom_fields', 10, 2);

    function require_custom_fields($result, $EM_Event) {
    if (empty($_REQUEST['em_attributes']['Region']) || $_REQUEST['em_attributes']['Region'] == 'Please select') {
    $EM_Event->add_error(__('Select the region of the event.', 'events-manager'));
    $result = false;
    }
    if (empty($_REQUEST['em_attributes']['Admission']) || $_REQUEST['em_attributes']['Admission'] == 'Please select') {
    $EM_Event->add_error(__('Please specify whether admission is required for the event.', 'events-manager'));
    $result = false;
    }
    return $result;
    }

    You say:

    I want to display the categories for events and I’m using Divi. What shortcode do I need to add to display the events for the requested event category?

    I’m not sure what this means. If you’re asking what shortcode to use for displaying just a list of the events for a particular category you could use something like this:

    [events_list category=jazz]
    • This reply was modified 2 months, 2 weeks ago by joneiseman.
    • This reply was modified 2 months, 2 weeks ago by joneiseman.
    Thread Starter gudrun

    (@gudrunpetz)

    Good morning,

    Thanks for the add_filter, I’ll try it out.

    With the categories, I meant that when someone clicks on the category in the preview, they’ll be redirected to the category archive page.

    With “category=jazz,” I specify which category should be displayed; I mean the category archive page, which should be configured.

    If you are on the calendar page and you click on an event it will then bring up a preview and you can then click on the category it will then bring you to the Categories page. You can change the formatting of that page by going to Events > Settings then going to the formatting tab then enabling Super Advanced mode then select the Events Categories section and then change the “Categories list item format”.

    Thread Starter gudrun

    (@gudrunpetz)

    Hello, I think we’re talking past each other πŸ˜€

    Here’s the example page for the “Exhibitions” category: https://ostbayerische24.de/kategorie/ausstellungen
    This is what the category page should look like.

    The problem is that instead of two exhibitions, ALL events are listed.

    However, I only want to list the categories that are actually accessed. It should also be in a grid list.

    How can I adjust this?

    There is currently no way to do that. It would require custom coding.

    Thread Starter gudrun

    (@gudrunpetz)

    Hello, Unfortunately, the add filter with the country isn’t working.

    This error message is now displayed, even though the fields are filled in or the specified add filter is stored for the country:

    • The address of the venue is required.
    • The city of the venue is required.
    • The country is required.

    If I remove the add filter, “only” the message appears:

    • The country is required.

    Looks like the code I sent you still needs some modifications to get it to work properly.

Viewing 15 replies - 31 through 45 (of 49 total)
  • You must be logged in to reply to this topic.