Skip to Content Skip to Menu

How to add fields programatically?

  • cambler
  • cambler
  • OFFLINE
  • Posts: 19
  • Thanks: 0
  • Karma: 0
16 years 1 month ago #76464 by cambler
How to add fields programatically? was created by cambler
I have a component that I'm developing that requires two new fields in CB. I'd like to just put them in the existing contact tab. Both fields are simple integers and should be read-only.

Is there any example code on how to create fields programatically?

I'd like to just put that code into the installer PHP file for my component. I can already detect that CB is installed and I abort if it's not, so I know it's safe to do a SQL call on the CB tables.

Anyone?

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48541
  • Thanks: 8290
  • Karma: 1445
16 years 1 month ago #76470 by krileon
Replied by krileon on topic Re:How to add fields programatically?
Huh?

I don't get what you're trying to say, but big words always allude me.

I'll give a whack at it though.

I read it as you're trying to add new CB fields from a component instead of a plugin, correct?

If this is the case then you need to setup the INSERT queries to insert the new fields.

Here's an example straight from CB it self. Do NOT attempt to use this query, but use it as an example for building your own.

[code:1]
INSERT INTO `jos_comprofiler_fields` VALUES (42, 'username', 'username', '#__users', '_UE_UNAME', '_UE_VALID_UNAME', 'predefined', 0, 0, 1, 11, 0, 0, 0, NULL, '', 1, 1, 1, 1, 0, 1, 1, 1, 1, 'fieldMinLength=\nfieldValidateForbiddenList_register=http:,https:,mailto:,//.,<a,</a>,&#\nfieldValidateForbiddenList_edit=');
[/code:1]

You'll also need the table structure to understand what each comma means.

So here's the table structure. Each line represents a value before a comma.
[code:1]
`fieldid` int(11) NOT NULL auto_increment,
`name` varchar(50) NOT NULL default '',
`tablecolumns` text NOT NULL,
`table` varchar(50) NOT NULL default '#__comprofiler',
`title` varchar(255) NOT NULL,
`description` mediumtext NOT NULL,
`type` varchar(50) NOT NULL default '',
`maxlength` int(11) default NULL,
`size` int(11) default NULL,
`required` tinyint(4) default '0',
`tabid` int(11) default NULL,
`ordering` int(11) default NULL,
`cols` int(11) default NULL,
`rows` int(11) default NULL,
`value` varchar(50) default NULL,
`default` mediumtext,
`published` tinyint(1) NOT NULL default '1',
`registration` tinyint(1) NOT NULL default '0',
`profile` tinyint(1) NOT NULL default '1',
`displaytitle` tinyint(1) NOT NULL default '1',
`readonly` tinyint(1) NOT NULL default '0',
`searchable` tinyint(1) NOT NULL default '0',
`calculated` tinyint(1) NOT NULL default '0',
`sys` tinyint(4) NOT NULL default '0',
`pluginid` int(11) NOT NULL default '0',
`params` mediumtext,
[/code:1]

Good luck. :)


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • cambler
  • cambler
  • OFFLINE
  • Posts: 19
  • Thanks: 0
  • Karma: 0
16 years 1 month ago #76545 by cambler
Replied by cambler on topic Re:How to add fields programatically?
Yup, that was half of it. I found good example code in Fireboard, actually, where it creates a tab and adds the Fireboard fields to it.

In addition to the fields table, one also has to alter the main comprofiler table to add the fields and also create the tab (if one wants a tab).

But again, Fireboard's code made it clear how to do it!

Please Log in or Create an account to join the conversation.

  • nant
  • nant
  • OFFLINE
  • Posts: 12339
  • Thanks: 1467
  • Karma: 877
16 years 1 month ago #76547 by nant
Replied by nant on topic Re:How to add fields programatically?
I would use the API to do this - read the API documentation - you can add CB fields via a CB plugin.

See profilebook as an example.

Please Log in or Create an account to join the conversation.

  • cambler
  • cambler
  • OFFLINE
  • Posts: 19
  • Thanks: 0
  • Karma: 0
16 years 1 month ago #76551 by cambler
Replied by cambler on topic Re:How to add fields programatically?
Profilebook? Found it, I'll take a look.

Post edited by: cambler, at: 2008/10/07 03:17

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum