WordPress.org

Ready to get started?Download WordPress

Forums

Events Manager
[resolved] How to make an event attribute required (7 posts)

  1. jalbaiges
    Member
    Posted 2 years ago #

    I have added some event attributes and I would like that some of them could be required during event submission. Is there any way to do it?

    In a broader vision, it would be interesting knowing how to make a field (custom or not) required or not.

    Thanks in advance,

    Jaume

    http://wordpress.org/extend/plugins/events-manager/

  2. agelonwl
    Member
    Posted 2 years ago #

    not atm, however you can modify template at /templates/forms/event/attributes.php

    using templates - http://wp-events-plugin.com/documentation/using-template-files/

  3. jalbaiges
    Member
    Posted 2 years ago #

    Well, as it seems there is no easy way to do it, I have finally modified a couple of files. In case of others interest, here it is what I have done:

    1) Let's assume you have created an event attribute through EM settings. Let's call it "attribute1".

    2) Open classes/em-event.php.

    3) Add the following line below Field names area (around line 60). This will declare the attribute as a property for event class.

    var $event_attribute1;

    4) Add the following line inside get_post() function (around line 320). You will find a similar line for "event_name". Just put them together. This will request the value provided in the public form.

    $this->event_attribute1 = !empty($_POST['em_attributes']['attribute1'] ) ? wp_kses($_POST['em_attributes']['attribute1'], array()):'';

    5) Add the following code inside validate() function (around line 450). As mentioned, you will find a similar piece of code for "event_name". This will check if the value is non-empty.

    if( empty($this->event_attribute1) ){
    	$validate_post = false;
    	$this->add_error( __('attribute1').__(" is required.", "dbem") );
    }

    6) Open templates/forms/event-editor.php.

    7) Add the following code beside the input field in the event attributes section (around line 165). This will place the asterisk sign, showing to the user it is a required field.

    <?php echo $name == 'attribute1' ? $required : ''; ?>

    8) You're done.

    I feel this might not be the better way of achivieng this goal, so I will listen to your suggestions.

    Jaume

  4. agelonwl
    Member
    Posted 2 years ago #

    thanks for updating;

  5. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 2 years ago #

    it's a long explanation, but as you said there's a better way.

    In fact, it's not that complicated, you need to hook into the em_event_get_post and em_event_validate filters, which passes $result and $EM_Event.

    You can probably acheive the same result doing that and replace $this with $EM_Event in your changes

  6. jalbaiges
    Member
    Posted 2 years ago #

    Thank you, Marcus. Although I'm not so WP expert when talking about "hooking" and so on, I would like to leave my code as clean as possible, so I will try your suggestion.

  7. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 2 years ago #

    this is the best place to start then - http://codex.wordpress.org/Plugin_API

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.