Home · Links · Contact Us
Home arrow Documentation arrow Customization arrow Adding a custom field (by example)
Home
Features
FAQ
Screen Shots
Modules
Themes
Demos
Documentation
Forums
Contact Us
Download
Purchase
Quotes

" ... I want to tell you that your thyme product is functional and valuable beyond words. I cannot imagine why any portal would be without it. It is the cornerstone of our new project ..."

" ... Thanks for such a complete project, its making my job much easier. ..."

" ... I have now deployed 4 different calendars and our users love them ... "

" ... Easy to install and use and a great look/design. ..."

" ... This has to be the easiest to use program I think I've had to deal with at all this year. ..."


Adding a custom field (by example) Print
To add a new field to an event, you must first add the field to Thyme's Events table using an SQL administration program such as phpMyAdmin. Given the many different SQL programs as well as the differences between the database servers that Thyme supports, doing this is beyond the scope of this document. Let's assume that a field called 'price' has been added to the Events table.

Once the field is added to the table, rows must be added to include/templates/event_edit_tpl.php and include/templates/event_view_tpl.php so that users may edit and view the field. This is described below.

There are 2 objects we will be working with; $_cal_tmpl and $_cal_form. An overview of each of the 2 objects follows before the actual custom field example.



$_cal_tmpl

This section is a broad overview of the $_cal_tmpl object and not part of the actual example of adding fields.

$_cal_tmpl is Thyme's template object. This creates sections (tabs) and rows. To create a new section, you simply add:


$_cal_tmpl->new_section("My Tab");


$_cal_tmpl->end_section();



It is important that you only add a new section after an existing section has been closed with $_cal_tmpl->end_section(). It is also important that you close your new section with $_cal_tmpl->end_section().

There are 2 methods used to place content inside a section; $_cal_tmpl->section_row() and $_cal_tmpl->new_row()/end_row().

$_cal_tmpl->section_row() takes 2 arguments; the row label and the row content. E.g.


$_cal_tmpl
->section_row("My Row Header", "This is some text");


$_cal_tmpl->new_row()/end_row() do not take any arguments. This is used to add a row that takes up the entire width of the section. E.g.



$_cal_tmpl
->new_row();

echo(
"This is some content ...");

$_cal_tmpl->end_row();



A complete example may look like this:



$_cal_tmpl
->new_section("Hello World");

$_cal_tmpl->section_row("Hello what?", "World");

$_cal_tmpl->end_section();




This example does not allow a user to enter data. It is simply to exemplify the $_cal_tmpl object. In most cases, you will not create your own section. You will instead add one or more rows to the General section of the template. Though it is completely up to you.

You may see lines through existing rows to separate data entry. For instance, there is a line between the E-mail and URL rows. This is printed using:



$_cal_tmpl
->section_spacer();





This takes no arguments, and again, just prints a line to separate rows.




$_cal_form

This section is a broad overview of the $_cal_form object and not part of the actual example of adding fields.

$_cal_form is Thyme's form object. It is used to display most of Thyme's data entry inside event_edit_tpl.php. There about as many methods as there are form elements. The one rule that applies to all of the methods is that the first argument is the name of the element and is required. Below are some of $_cal_form's form element methods and their arguments.






$_cal_form
->textbox($name, $size, $extra);



Returns a text box.

$name is the name of the input element, $size is the size, and $extra may be anything. E.g.



echo($_cal_form->textbox("price", 32, " class='some_css_class'"));



Would print

<input type="text" name="price" size="32" class="some_css_class">

The only required argument is $name.








$_cal_form
->select($name, $options, $extra);



Returns a select box.

$name is the name of the select element, $options is an array containing options appearing in the select box, and $extra may be anything. E.g:



$prices
= array(
   
0 => "Free",
   
5 => "5 dollars",
   
10 => "10 dollars",
   
20 => "20 dollars");

echo(
$_cal_form->select("price", $prices));



Would print:

<select name="price">
<option value="0">Free</option>
<option value="5">5 dollars</option>
<option value="10">10 dollars</option>
<option value="20">20 dollars</option>
</select>


Both $name and $options are required.








$_cal_form
->checkbox($name, $extra);



Returns a check box.

$name is the name of the checkbox, and $extra may be anything. E.g.:



echo($_cal_form->checkbox('price') ." Non-free event.");



Would print:

<input type="checkbox" name="price"> Non-free event

$name is the only required field.






Adding a custom field example


This assumes you have already added a 'price' field to Thyme's Events table as described in the begining of this tutorial.

For our example, we'll make price a text box allowing users to enter their own price. Instead of creating an entire new section for this, we'll just add it to the existing section "General". Specifically, we want to add it just above the "Name" row.

Open include/templates/event_edit_tpl.php in a text (or PHP) editor and search for _NAME_. You will see the line that prints the "Name" row:



$_cal_tmpl
->section_row(_NAME_, $_cal_form->textbox('org_name', 30));



Now let's add the price row. We'll also want to add a spacer to visually separate Price from Name. The resulting addition should look like this:



$_cal_tmpl
->section_row("Price", $_cal_form->textbox('price', 6));

$_cal_tmpl->section_spacer();

$_cal_tmpl->section_row(_NAME_, $_cal_form->textbox('org_name', 30));



After this is added, save the file, then upload it to your web server.

When editing an event, you will see that Price now appears above Name.


It is VERY important that the form element name be the same as the column name added to Thyme's Events table. We added the column 'price' to the table and we used 'price' as the name argument for $_cal_form->textbox.

Entering data in the price text box and saving the event will now save the data to the price column. Thyme will handle saving the data as well as populating the price text box with the value when editing an event. Note that at this stage, you will only see Price when editing or adding an event.






Next we'll want to display the price field when viewing an event. This is done in include/templates/event_view_tpl.php. It uses the same template object ($_cal_tmpl) as event_edit_tpl.php. Likewise, rows are added in the same manor. This time we just want to display the price data.

Let's add the row just above the Notes row. To do this, edit the file in a text (or PHP) editor and search for 'notes'. You should see a snipped such as:



# notes
############
if(strlen($_cal_event->notes) > 0) {



We'll add our price row just above that. Thyme holds the current event in it's $_cal_event object. Since we have added the price field to the Events table, a property called 'price' is now available in $_cal_event. To add our row, insert the following above the notes snippet:



$_cal_tmpl
->section_row("Price", $_cal_event->price);

# notes
############
if(strlen($_cal_event->notes) > 0) {



We could choose to skip displaying this field if it has no data:



if($_cal_event->price)
   
$_cal_tmpl->section_row("Price", $_cal_event->price);

# notes
############
if(strlen($_cal_event->notes) > 0) {



We may even display something different depending on the value of price.



if(!$_cal_event->price) {

   
$_cal_tmpl->section_row("Price", "Free !!!");

} else {

   
$_cal_tmpl->section_row("Price", $_cal_event->price);

}
# notes
############
if(strlen($_cal_event->notes) > 0) {


Once this is done, save the file and upload it to your web server. The Price row now appears when viewing an event.





That's it. You may add as many custom fields as you wish.
 
It's all about you!
Does Thyme lack a feature you want? How may we improve it?

Buy Now
  • Secure Checkout
  • Simple, web-based installation
  • PayPal accepted

Test Drive
Download our free, 30-day trial version with no obligation to buy.

The trial download contains all the same features as the full version, so you know exactly what you're getting!

Latest Updates
© 2005 eXtrovert software unless otherwise noted. All rights reserved.
Portions © 2004 Ben Brown. All rights reserved.
Trademarks are property of their respective owners.