| View previous topic :: View next topic |
| Author |
Message |
Kent Guest
|
Posted: Thu Jan 19, 2006 6:04 pm Post subject: Custom fields for events? |
|
|
I'm wondering how I can add custom fields for the events.
Thanks,
Kent |
|
| Back to top |
|
 |
esoft_ian
Joined: 12 Sep 2005 Posts: 5275
|
Posted: Thu Jan 19, 2006 7:14 pm Post subject: |
|
|
Hi Kent,
This will require some PHP knowledge. You may add custom fields to events by:
Let's say the field is called Price.
1) Adding the field to the Events table. You may do this through any SQL server admin program. MyPHPAdmin etc.. Create a field in the table called Price.
2) Adding the field to include/templates/event_edit_tpl.php. Add a text box to the form where users may enter a price. Make sure to name the text box 'Price'. You can do this by adding something like:
$_cal_tmpl->section_row("Price", $_cal_form->textbox('Price'));
3) Adding Price to include/templates/event_view_tpl.php. You could do something like:
$_cal_tmpl->section_row("Price", $_cal_event->Price);
Don't hesitate to ask any questions if you have them. |
|
| Back to top |
|
 |
Kent Guest
|
Posted: Thu Jan 19, 2006 10:16 pm Post subject: |
|
|
I'm amazed at your response time to answer these questions.
Thank-you very much! And I think I forgot to say thank-you for your solution to my previous question. It was just what I needed.
Kent |
|
| Back to top |
|
 |
Phil Guest
|
Posted: Mon Jan 23, 2006 7:37 pm Post subject: |
|
|
Hi,
Related to this, is it possible to then retrieve the new field data using Thyme's API (eg using something like
$e->price
or would I need to re-query the database to retrieve this?
Thanks
Phil |
|
| Back to top |
|
 |
patrick
Joined: 10 Sep 2005 Posts: 70
|
Posted: Mon Jan 23, 2006 7:45 pm Post subject: |
|
|
Everything that is a field in the Events table is available as $e->field. If you added Price, it would be available as $e->Price. No separate query is needed.
Though it's not exactly point-and-click yet, we've tried to make it as easy as possible for someone with a little PHP experience to be able to add a field. |
|
| Back to top |
|
 |
Phil Guest
|
Posted: Tue Jan 24, 2006 2:54 pm Post subject: |
|
|
Thanks Patrick, that makes life a lot easier...
I do think you've done a great job with this - well done.
Phil |
|
| Back to top |
|
 |
smeallum
Joined: 17 May 2006 Posts: 177
|
Posted: Wed Jul 05, 2006 4:36 am Post subject: |
|
|
Hi, i will need to add several custom fields...i think i could do with adding them to the events table as explained before on this post.
But for my specific needs, some of those new fields will be applicable to a certain category only and so on, so lets's say i have categories "Category1", "Category2" and "Category3". I would add custom fields to events table: "custom1", "custom2", "custom3", "custom5", "custom6" and "custom8".
I need that when a user adds/requests an event, some of those custom fields are shown depending on the category selected.
For example if "Category1" is selected custom fields "custom1" and "custom2" would be available in the form. If the user selects "Category2" then the custom fields applicable before, would be hidden and "custom3" and "custom3" would be shown...
Of course an equivalent behaviour would need to take place when modifying an event.
Any hints on how to do this?
Many thanks...
Cheers,
NiCo  |
|
| Back to top |
|
 |
esoft_ian
Joined: 12 Sep 2005 Posts: 5275
|
Posted: Wed Jul 05, 2006 11:19 am Post subject: |
|
|
Something like this:
| Code: |
$_cal_tmpl->new_row();
echo("<span id='opt1span' style='display: hidden'>")
echo($_cal_form->checkbox('opt1') .' Option 1');
echo("</span>");
.. more spans with options ..
$_cal_tmpl->end_row();
|
.. modify the category select box and add a 3rd agument:
| Code: |
$_cal_form->select("type", array('('._NONE_.')') + $_cal_event->cal_etypes,
" onChange='upd_opts()'") |
.. add a javascript function to handle this:
| Code: |
function upd_opts() {
var catsel = document.EventForm.elements['type'].selectedIndex;
if(catsel == 1) {
document.getElementById('opt1span').style.display = 'inline';
document.getElementById('opt2span').style.display = 'none';
} else ..
}
|
} |
|
| Back to top |
|
 |
smeallum
Joined: 17 May 2006 Posts: 177
|
Posted: Wed Jul 05, 2006 5:53 pm Post subject: |
|
|
Sorry,
but that first piece of code in your last message, in what file must it go?
If it is in /include//templates/event_edit_tpl.php does it mean that it goes instead of $_cal_tmpl->section_row("Price", $_cal_form->textbox('Price')); ?
So i would add as you mentioned:
$_cal_tmpl->new_row();
echo("")
echo($_cal_form->textbox('Price') .'Price: ');
echo("");
$_cal_tmpl->end_row();
And then i would add all my other custom fields in the same manner between that new_row() and end_row()?
Cheers,
NiCo  |
|
| Back to top |
|
 |
esoft_ian
Joined: 12 Sep 2005 Posts: 5275
|
Posted: Wed Jul 05, 2006 5:56 pm Post subject: |
|
|
| Yep |
|
| Back to top |
|
 |
smeallum
Joined: 17 May 2006 Posts: 177
|
Posted: Wed Jul 05, 2006 10:27 pm Post subject: |
|
|
Cool...
I am working on that now
how do i set any of those custom checkboxes to be "checked" by default?
Also... how can i have the labels bold? The reson why i ask is because If i would have done $_cal_tmpl->section_row("Price: ", $_cal_form->textbox('Price')); then the label "Price: " would have been bold and the label and the textbox, alligned with the standard fields, but if i put that inside a span and between new_row()/end_row() then the label is not bold and the aligment is completely to the left.
Cheers,
NiCo |
|
| Back to top |
|
 |
esoft_ian
Joined: 12 Sep 2005 Posts: 5275
|
Posted: Wed Jul 05, 2006 10:53 pm Post subject: |
|
|
Hi,
Defaults:
Do: $form->defaults['opt1'] = 1;
before you print the form element.
Bold:
Wrap the label around <b> </b> tags. |
|
| Back to top |
|
 |
smeallum
Joined: 17 May 2006 Posts: 177
|
Posted: Thu Jul 13, 2006 2:58 am Post subject: |
|
|
In case somebody goes through this to add custom fields that show depending on the event category chosen, there is a small error in part of the code mentioned in this thread:
| ian wrote: |
| Code: |
function upd_opts() {
var catsel = document.EventForm.elements['type'].selectedIndex;
if(catsel == 1) {
document.getElementById('opt1span').style.display = 'inline';
document.getElementById('opt2span').style.display = 'none';
} else ..
}
|
} |
in that function, .value should be used instead of .selectedIndex
Cheers,
NiCo  |
|
| Back to top |
|
 |
smeallum
Joined: 17 May 2006 Posts: 177
|
Posted: Fri Jul 14, 2006 2:57 am Post subject: |
|
|
Hi...
I was wondering if there is a way that i can define that a textbox will only allow numeric data to be entered(actually numbers with decimal too). I don't want the user to be able to type letters.
Or is it the only option to do it when validating the data in the Onsubmit part?
Cheers,
NiCo |
|
| Back to top |
|
 |
smeallum
Joined: 17 May 2006 Posts: 177
|
Posted: Thu Jul 20, 2006 6:04 am Post subject: |
|
|
i just need to know, since there might be a class property specifically for that. Or do i just ned to work it on the Onsubmit part?
Cheers,
NiCo |
|
| Back to top |
|
 |
|