Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
[howto] How to add more Form types
Just a quick how-to if you’d like more form types for organizational purposes (I’ll be adding type ‘bert’ as an example):
a) Open up /include/txp_form.php in your favorite text editor.
b) line 228, this validates the form type on entry:
if (!in_array($type, array('article','bert','category','comment','file','link','misc','section')))
c) lines 281 & 282, this is for the drop down when selecting type on new form entry:
$types = array(''=>'','article'=>'article','bert'=>'bert','category'=>'category','comment'=>'comment',
'file'=>'file','link'=>'link','misc'=>'misc','section'=>'section');
d) line 290, this saves the toggle state when returning to the forms tab:
$panes = array('article', 'bert', 'category', 'comment', 'file', 'link', 'misc', 'section', 'article-tags', 'link-tags', 'comment-tags', 'comment-detail-tags', 'comment-form-tags', 'search-result-tags', 'file-tags', 'category-tags', 'section-tags');
That’s it, now you can create as many form types as you like.
We Love TXP . TXP Themes . TXP Tags . TXP Planet . TXP Make
Offline
Re: [howto] How to add more Form types
Oh very nice Bert and as I’ve already modified txp_form.php …
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
Re: [howto] How to add more Form types
Why type of forms was hardcoded?..
Other hack:
a) Open up /include/txp_form.php in your favorite text editor.
b) replace
if (!in_array($type, array('article','category','comment','file','link','misc','section')))
to
if (!(in_array($type, array('article','category','comment','file','link','misc','section') )|| in_array($type, safe_column("type", "txp_form", "1=1 GROUP BY type"))) )
c) add after line
$types = array(''=>'','article'=>'article','category'=>'category','comment'=>'comment', 'file'=>'file','link'=>'link','misc'=>'misc','section'=>'section');
this line
$types=array_merge($types, safe_column("type", "txp_form", "1=1 GROUP BY type") );
d) add after line
$panes = array('article', 'category', 'comment', 'file', 'link', 'misc', 'section', 'article-tags', 'link-tags', 'comment-tags', 'comment-detail-tags', 'comment-form-tags', 'search-result-tags', 'file-tags', 'category-tags', 'section-tags');
this line
$panes=array_merge($panes, safe_column("type", "txp_form", "1=1 GROUP BY type") );
Now you may use any type
which is in the table txp_form
.
For new type
form: once modify field type
for one existing record in txp_form
table via phpMyAdmin.
aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_dragdrop : Drag&Drop categories (article, link, image, file)
Offline
Re: [howto] How to add more Form types
makss wrote:
Other hack:
You know, I completely forgot about this. It’s pretty simple to do in the core and it’s been one of the things I’ve thought would be very useful for most people’s organisational well-being, especially after the collapsible list was introduced in 4.3.0.
Looking at your code, if I was doing it for real I’d see if it could be optimized a bit (e.g. array_merge is expensive: concatenation might be quicker in places) and try to cache the safe_column()
to save a query if possible — I haven’t looked at the core code yet. But in essence I like your approach, thanks for posting. If nobody objects I’ll try something like this in the core and make it official.
One other thing I’ve never understood is that if the Form type is required, why is there an empty item at the top? It’s just one more click if you’re creating an article type Form… anybody know why it’s there?
Last edited by Bloke (2012-01-04 21:51:39)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: [howto] How to add more Form types
Bloke wrote:
If nobody objects I’ll try something like this in the core and make it official.
Thanks
Other small and useful trick: please add in tabletxp_form
field modified
(or LastMod
) with type timestamp.
- I have many forms and I do not remember when I edited them for the last time. Sometimes I need to find out what forms have changed in recent time to correct the errors.
- I want to cache some form and I need a marker(field
modified
) to determine whether that form has not changed.
Need add to txp_form.php
code like this:
safe_insert('txp_form', "Form = '$Form', type = '$type', name = '$name', modified=now() ");
and
safe_update('txp_form', "Form = '$Form', type = '$type', name = '$name', modified=now() ", "name = '$oldname'");
and add some code for display modified field in admin interface.
.
Low priority tricks:- add field
modified
fortxp_page
- display last modified time in admin interface
- add field
modified
fortxp_css
- display last modified time in admin interface
- add
Last-Modified
header in functionoutput_css
for browser caching.
aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_dragdrop : Drag&Drop categories (article, link, image, file)
Offline
Re: [howto] How to add more Form types
Shhhhh, anyone wanna try this altered Form panel out where you can create as many types as you like? Just download the code, backup your existing include/txp_form.php
and overwrite it with this one.
Feedback welcome, especially on the usability/theming front since it’s quite crude to just stuff a text box next to the select list without any wrapping or labels. /me dreams of a native combo box HTML input.
Note that to alter a Form’s type you just type a new one or select one of the new types from the list. If you type anything in the box it is used in lieu of your selection. This means that the first empty element in the select list is not strictly necessary but some people might prefer to select the empty one first as an explicit “I have chosen no type” and then “I am now typing a new one” as a visual safety net (albeit one with no actual net!), thus I think it should stay in the list for that reason alone.
Please everyone test it and let me know:
- if it’s any good
- if it’s worthy of being in the core
- how to change it so it is worthy of being in the core
- whether to drop the idea and go and become a florist in Honolulu
makss wrote:
Other small and useful trick: please add in table txp_form field modified
One thing at a time… which reminds me to also look at the essential forms thing one day…
Last edited by Bloke (2012-01-04 21:55:54)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
#7 2012-01-05 00:08:14
- GugUser
- Member
- From: Quito (Ecuador)
- Registered: 2007-12-16
- Posts: 1,473
Re: [howto] How to add more Form types
@ Bloke:
Thank you for that. I think that’s a very good change. But it lacks the ability to delete the owns and the defaults form types. This should be in the core.
Offline
Re: [howto] How to add more Form types
GugUser wrote:
it lacks the ability to delete the owns…
Once you no longer use a form type of your own (i.e. you delete / reassign all forms under its name) then it is deleted automatically. Or at least, that’s what it should do. Is it not doing that for you?
…and the defaults form types
cf. essential forms. Until that mess is sorted out, the default types are fixed and undeletable. Even once the core forms are consolidated, some special types (e.g. article) will still not be deletable. It causes too much of a support headache.
Last edited by Bloke (2012-01-05 00:24:03)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
#9 2012-01-05 00:59:20
- GugUser
- Member
- From: Quito (Ecuador)
- Registered: 2007-12-16
- Posts: 1,473
Re: [howto] How to add more Form types
Bloke wrote:
Once you no longer use a form type of your own (i.e. you delete / reassign all forms under its name) then it is deleted automatically. Or at least, that’s what it should do. Is it not doing that for you?
Yes, it’s doing that.
Offline
Re: [howto] How to add more Form types
Bloke wrote:
try this altered Form panel out where you can create as many types as you like?
Thanks! It’s work fine!
Small fix in Line 302
, set class
and size
return selectInput('type', $types, $type) . fInput('text', 'new_type', '', 'edit','','',15);
aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_dragdrop : Drag&Drop categories (article, link, image, file)
Offline
Re: [howto] How to add more Form types
makss wrote:
Small fix in
Line 302
, setclass
andsize
Good catch, thanks. I’ll add that later once I’ve finished constantly retuning my new Ukulele every 8 chords or so (bah! new strings syndrome…)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
#12 2012-01-05 12:55:01
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,311
Re: [howto] How to add more Form types
Strikes me that the field shouldn’t show up on the default form page.
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline