Entering 0 for Free events on front-end submission form ERRORs

Home Forums Calendar Products Community Events Entering 0 for Free events on front-end submission form ERRORs

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1288131
    picturepark
    Participant

    Entering 0 for Free events on front-end submission form ERRORs with “Event Cost is required” (see screenshot).

    However, a 0 is enterable on the Events’ Admin page.

    Was this changed? If so, the text below the field needs to be changed, as it says: “Leave blank to hide the field. Enter a 0 for events that are free.”

    Or is this a bug?

    Please advise.

    Thanks,
    Michael

    #1288133
    picturepark
    Participant

    Tried editing the above, but ran out of time. I added that we’d used the following function from this Knowledgebase to set the required fields: https://theeventscalendar.com/knowledgebase/required-fields-for-events-submission-form/#default-fields

    `add_filter( ‘tribe_events_community_required_fields’, ‘my_community_required_fields’, 10, 1 );

    function my_community_required_fields( $fields ) {
    $fields = array(
    ‘post_title’,
    ‘post_content’,
    // ‘EventCost’,
    ‘EventURL’,
    ‘EventStartDate’,
    ‘_ecp_custom_5’,
    ‘_ecp_custom_12’,
    ‘_ecp_custom_13’,
    );

    return $fields;
    }`

    Did something change to break this function?

    I’ve commented out the ‘EventCost’ line for now to prevent the error. If there is no other fix, we’ll need to edit the line below — “Leave blank to hide the field. Enter a 0 for events that are free.” — to have people enter “Free”, which it seems to take with the field set to required.

    Thanks,
    Michael

    • This reply was modified 6 years, 11 months ago by picturepark.
    #1288683
    Victor
    Keymaster

    Hi Michael!

    Thanks for reaching out to us! 🙂

    Unfortunately, this is a small issue regarding the cost validation that won’t take into account when the cost is ‘0’.

    I’ve come up with a code snippet to validate the cost and be able to input ‘0’ as value >

    /* Custom Event Cost validation */
    function tribe_custom_event_cost_validation ( $valid, $submission, $class ) {
    /* Prevents submit and adds error message if cost is empty and different than '0' */
    if ( empty( $submission['EventCost'] ) && $submission['EventCost'] != '0' ) {
    $valid = false;
    $message = __( '%s is required', 'tribe-events-community' );
    $message = sprintf( $message, 'Event Cost');
    $class->add_message( $message, 'error' );
    }
    return $valid;
    }
    add_filter('tribe_community_events_validate_submission', 'tribe_custom_event_cost_validation', 10, 3);

    Just remember to not include the ‘EventCost’ field in the my_community_required_fields() function you already have.

    I hope that helps and let me know if you have any other questions.

    Best,
    Victor

    #1288698
    picturepark
    Participant

    Hi Victor,

    Thanks that seems to work, however the cost field is now not marked with an asterisk like the other required fields, and upon validating, it puts the note at the top, but the field below is not highlighted, so it’s not as easy to spot what the error refers to when scrolling down.

    Is there anyway to also correct those issues too, so it behave like the regular required fields?

    Thanks,
    Michael

    #1289008
    Victor
    Keymaster

    Hi Michael!

    Thanks for coming back an trying that out! 🙂

    Yes, you are right. It does not add the “required *” text to the field, nor the field error message.

    The article about the required fields is only suggested as a starting place. Just to set expectations right, we are fairly limited in how much support we can give for customizations like this.

    That said, we really like helping out and at least point you in the right direction, so let me do that.

    Here’s the complete code snippet I’ve put up to also add the “required” text to the cost field. Still this does not shows the validation error message for the field, but at least users will know it’s required.

    https://gist.github.com/vicskf/f4dc5cf320106ce0b59a3a5f7f547f3f

    Let me know if other questions.

    Cheers!
    Victor

    #1299194
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Entering 0 for Free events on front-end submission form ERRORs’ is closed to new replies.