Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2006-03-21 12:08:23
- M_i
- Member
- Registered: 2006-03-05
- Posts: 122
drop down lists for custom fields
Dear all,
My site relies heavily on custom fields, and with that it relies on these custom fields being filled out to exactly match previous values.
More often than not, my custom fields have only a limited range of possible values. For example, one custom field will either be filled with ‘yes’ or ‘no’; another one with ‘red’ or ‘blue’ or ‘yellow’ or ‘green’ or ‘purple’.
For my site, and I think for many more sites that like mine, allow members to enter articles, it would be very helpful if there’d be a plugin that would allow one to enter a list of all possible values of a custom field, which in the editing screen would appear as a drop down list.
That way, there will be no typos (‘yess’ instead of ‘yes’) or mismatched values (‘violet’ instead of ‘purple’) that stop articles appearing in the appropriate article lists.
And it would make the form a lot more user friendly. Instead of having to provide detailed instructions on what members should type in which fields (always a guess whether or not they’ll actually read them), members are confronted with a limited amount of options.
Looking forward to hearing what you think,
- Iris
Offline
Re: drop down lists for custom fields
I second that request, well not sure if exactly “Drop down lists” but something that expand the possibilities to “adapt” the TXP Write Tab to different kind of contents/sites.
I posted before a request ( Porting MT Right Fields to TXP ) to implement something like the Plugin “Right Fields” for Movable Type, that approach it’s awesome! but the only problem is that I prefer Textpattern to MT and wish something like that here!
Other approach is the TXP Plugin jmc_event_manager that plugin adds new tables to the database and a new TAB with new forms to insert other information than the usual news/articles.
Anyway, drop down lists in custom fields could help (but I wish a little more).
Offline
Re: drop down lists for custom fields
M_i wrote:
… it would be very helpful if there’d be a plugin that would allow one to enter a list of all possible values of a custom field, which in the editing screen would appear as a drop down list.
Hi Iris, I managed to hack TXP a while back in order to get a similar functionality to what you are after. If interested, drop a line.
Last edited by gerhard (2006-03-21 17:38:00)
Offline
Re: drop down lists for custom fields
gerhard wrote:
M_i wrote:
… it would be very helpful if there’d be a plugin that would allow one to enter a list of all possible values of a custom field, which in the editing screen would appear as a drop down list.
Hi Iris, I managed to hack TXP a while back in order to get a similar functionality to what you are after. If interested, drop a line.
Gerhard, that’s great! I really want to know how to do something like that!
A Plugin would be great but if not a hack …
Last edited by duchamp (2006-03-21 17:48:43)
Offline
#5 2006-03-21 18:47:03
- M_i
- Member
- Registered: 2006-03-05
- Posts: 122
Re: drop down lists for custom fields
duchamp wrote:
gerhard wrote:
Hi Iris, I managed to hack TXP a while back in order to get a similar functionality to what you are after. If interested, drop a line.
Gerhard, that’s great! I really want to know how to do something like that!
A Plugin would be great but if not a hack …
Second that! Looks perfect – exactly what I want. Tried a hack myself but couldn’t get it to work like that.
Offline
Re: drop down lists for custom fields
Gerhard, a third “I’m interested too”. Makes life for the end user a good deal easier
TXP Builders – finely-crafted code, design and txp
Offline
#7 2006-03-21 21:53:23
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: drop down lists for custom fields
Me too ;)
Offline
Re: drop down lists for custom fields
Indeed.
Offline
Re: drop down lists for custom fields
It’s not easy but I’m trying … and seems to work!
1) I created a new Custom Field in Admin > Advanced Prefs
the Custom Field #3 now is named Colour
2) Open txp_article.php and:
a) modify the custom field #3 near Line 371 to this:
<code>($custom_3_set) ? newCustField( 3, $custom_3_set, $custom_3 ) : ‘’,</code><br />
b) I created the Function newCustField to give some value to $custom_3
this goes around line 617:
<code> function newCustField($num,$field,$content) { $name = (‘custom_’.$num); $arr = array( ‘white’ => ‘white’, ‘blue’ => ‘blue’ ); return graf($field . br . selectInput($name,$arr,$content)); }</code>
allright, the Drop down appear into the Form with both values White or Blue and the Selected value is assigned to the Custom Field!
What else?
Create the other INPUT variants like radio and checkbox … Wow! This is great!
Last edited by duchamp (2006-03-22 14:02:27)
Offline
Re: drop down lists for custom fields
ooooh, that would take txp to a whole new level!
~~~~~~~~~~~~~| monolinea.com | pixilate.com | istockphoto.com/kemie |~~~~~~~~~~~~~
Offline
Re: drop down lists for custom fields
Well, well … I updated my previous post (before Kemie’s post) with the “right” code and it’s working!
Last edited by duchamp (2006-03-22 14:33:04)
Offline
#12 2006-03-22 16:02:58
- M_i
- Member
- Registered: 2006-03-05
- Posts: 122
Re: drop down lists for custom fields
duchamp wrote:
Well, well … I updated my previous post (before Kemie’s post) with the “right” code and it’s working!
That’s wonderful! Thanks duchamp!
Building on your work, I got this together for occasions where you just need on / off or yes / no (i.e. 1 or 0):
<code>function radioCustField($num,$field,$content)
{
$name = (‘custom_’.$num);
return graf($field . br . yesnoRadio($name,$content)); }</code><br><br>
You can replace ‘yesnoRadio’ with ‘onoffRadio’ if you want your options to be on/off instead of yes/no; or with ‘checkbox’ for, well, the checkbox – also see lib/txplib_forms.php
Of course the line of the custom field you want to use this for needs to read:
($custom_3_set) ? radioCustField( 3, $custom_3_set, $custom_3 ) : '',
<br><br>
I don’t know if I’ve done this correctly (that is, according to the rules of the art), because honestly, I have no training in this besides trial & error. But it puts 1s and 0s in the right places in the database – and for now, that’s good enough for me.
- Iris
Offline