A little bit of everything…
RSS icon Home icon
  • Custom data in EventList frontend event submission form

    Posted on March 15th, 2009 Aleix 2 comments

    This is (a quickly written and) the last planned post of the EventList 1.0RC Component for Joomla 1.5 customization series, and in response to Junkah’s request. It explains how to add custom fields in the event submission form; the example below is a text field where the number of available places can be specified. The example only covers the process of saving the submitted number in the database, so that it can be kept for future reference. If you wish to prevent further registration of guests once the number has been reached, then you will have to write some extra code for that purpose, but as I said this is beyond the scope of this post.

    My apologies for not having all the free time I’d like to, for adding new contents more often and for writing with more details. Back to university, it’s all about priorities. It will be like this for some months, but I will do my best to keep up the knowledge sharing!


    First of all…

    … I would like to mention something. It has been several months since I did this process below in a live website, and I did it only once. It took me a while to figure out how everything works. Now I write how to do the process here, doing my best to remember how I achieved the results back then and checking the code. But please, excuse me if I forgot some part of the process (in step two) and it doesn’t work to you. If this happens, let me know with a comment at the end of the post and I will look thoroughly on what’s missing. If it directly works, then great!

    Now let’s do it.


    Step one: modifying the database

    Logically you want the information submitted by the user to be stored… in the database. So the first thing you should do is add a custom row to the already existing jos_eventlist_events table. Why there? The answer is simple: you want to treat this data as individual for each event, so in the same way you would store the date of the event in the events table, you should store there too any other data directly connected to specific events.

    Custom row (click to enlarge)

    Custom row (click to enlarge)

    See the structure of the table at the picture to the right? Everything should look familiar; as a matter of a fact all of the rows should be on default in your table too, except the one highlighted in red: this is a custom added row. The name of it is maxassistents, which is a shortened version of maximum number of attendees in my language.

    When adding the new row, remember to select the correct type of content according to your intentions: varchar, int, etc.


    Step two: modifying the processing code

    I will go straight to the point here, not that it would become too tedious or confusing.

    Open the following file:

    components/com_eventlist/models/editevent.php

    Now find a comment line in the code (within function &getEvent(  )) where it says:

    //prepare output

    You will see it is followed by many lines which look similar to each other, and to the one below. Add this one next:

    
    $this->_event->maxassistents        = 0;
    

    This actually resets the variable value when getting a new event. Each of those several lines actually resets a different variable.

    Now open:

    administrator/components/com_eventlist/tables/eventlist_events.php

    Find the lines:

    /** @var date */
    var $checked_out_time     = 0;
    

    And add immediately next to them:

    /** @var int */
    var $maxassistents        = 0;
    

    Notice how the nature of the variable is declared: integer, date, string, etc. so do so as appropriate for your variable.


    Step three: modifying the layout

    Nothing really worth saying here, apart from the code.

    Open the layout file:

    components/com_eventlist/views/editevent/tmpl/default.php

    And add, where the other form items are placed:

    
    <label for="el_assistents">
    
    </label>
    <input id="maxassistents" class="inputbox validate-assistents" maxlength="3" name="maxassistents" size="5" value="<?php echo $this->row->maxassistents; ?>" />
    

    I recommend you look the code of the other form elements so you see how the CSS styles are applied to them. It is not really difficult to copy those styles to the newly created form element or adding new ones.

    Finished and styled (click to enlarge)

    Finished and styled (click to enlarge)

    I wish all this stuff proves to be useful :)

     

    Related posts:


     

    2 responses to “Custom data in EventList frontend event submission form”

    1. Hi

      Great work …

      Was just wondering if you have a similar workaround to link the registered users of an event to mass mail component. I would like to be able to easily mail all registered users of an event …

      Thanks

    2. Hello,

      Unfortunately I don’t think I will write a tutorial about this, because this version of EventList 1.0 RC is outdated and I ignore if the steps apply for EventList 1.0 stable, which is the version everytime more and more people are using since few months ago. But I can guide you a bit with what would be my approach to the issue:

      1. Create a new PHP file, which you will link from wherever you want in the EventList template (external file so not to mess EL code)

      2. (this will allow everyone to use mass mail; so if you want to restrict this to admins use the appropriate Joomla function to check user level and display only to admin) When you link it, append a GET variable to make reference to the event ID the registered people of which will get e-mail. To dynamically retrieve the Event ID, you can use the specific EL function (you’ll find it anywhere in the code where reference is made to the event ID).

      3. In this PHP file, build a simple form with the necessary fields for e-mail (subject & message at least). Retrieve the event ID from the URL using $id = $_GET['id']. Submit button too.

      4. On submit, the PHP script to run must:

      - First, fetch users registered to the specific event (MySQL query table ‘jos_eventlist_register’, selecting all rows where event = event ID, retrieve the column uid for each (this is the Joomla user ID, we’ll need it to find every email address).

      - Then, with the resulting user IDs, you can query table ‘jos_users’ to gather each e-mail address from registered users. Select all rows where id matches the retrieved ones, then retrieve e-mail from column ‘email’

      5. Put all e-mails together separated with commas, using a loop. Then make the whole resulting string be recipient value for PHP mail function.

      That was it. This is just an improvised summary of the steps of a possible approach. I know it might sound a bit confusing, you’ll need good PHP knowledge to make all this. But as far as I can think about, there’s no easier way. I ignore if 1.0 stable provides a built-in mass-mail function. Hope it helps, though.

    Leave a reply