Page 1 of 1

adding fields to contacts component

Posted: Thu Sep 24, 2009 7:11 pm
by goltoof
I'm attempting my first core hack of the contacts component. I'm displaying multiple contacts in category layout and simply want to add additional input fields that aren't currently available (ie, company, region etc)

It looks like I've got most of it down. Here's what I've done so far:

/com_contact/admin.contact.html.php
Added just above contact position around line 355

Code: Select all

<tr>
<td class="key" valign="top">
<label for="region">
<?php echo JText::_( 'Region' ); ?>:
</label>
</td>
<td>
<input class="inputbox" type="text" name="region" id="region" size="60" maxlength="255" value="<?php echo $row->region; ?>" />
</td>
</tr>
/com_contact/config.xml
Added just above "contact's position" around line 29

Code: Select all

<param name="show_region" type="radio" default="1" label="Show Region" description="Show/Hide the Region">
<option value="0">Hide</option>
<option value="1">Show</option>
</param>
/com_contact/contact_items.xml
Added just below "name" area around line 17

Code: Select all

<param name="show_region" type="radio" default="1" label="Region" description="Show/Hide the region">
<option value="0">Hide</option>
<option value="1">Show</option>
</param>
/com_contact/tables/contact.php
Added just under "alias" string:

Code: Select all

var $region = null;
/** @var string */
In MySQL:

Code: Select all

mysql> ALTER TABLE jos_contact_details ADD region VARCHAR(60) AFTER alias;
Query OK, 13 rows affected (0.02 sec)
Records: 13  Duplicates: 0  Warnings: 0
When adding a contact, the field "Region" is there, gives me the option to hide it or not, and all the info saves just fine, but it's a no show on the page! It shows the spaces where the info should be but the text doesn't echo. Doesn't make sense since every other value is setup the same way. Which makes me think there's some other file outside of the com_contacts folder I need to adjust?

Re: adding more fields to contacts component

Posted: Mon Sep 28, 2009 3:18 pm
by goltoof
Anyone? I do believe this is the right forum for this, and there's just gotta be someone here who has an idea what pieces are involved with making this work. This seems like a very basic hack and it's important that I make this happen for the site I'm building. I'm surprised no one's ever tried this before.

Any feedback at all would be appreciated.

Re: adding more fields to contacts component

Posted: Mon Sep 28, 2009 4:19 pm
by Per Yngve Berg
components\com_contact\views\contact\tmpl\default_form.php

Re: adding more fields to contacts component

Posted: Mon Sep 28, 2009 4:39 pm
by goltoof
Per Yngve Berg wrote:components\com_contact\views\contact\tmpl\default_form.php
Thanks, but are you sure you understand what I'm trying to accomplish here? I'm not trying to change the contact form. I'm trying to change the administrative end of the Contacts component.

For clarification, go to Administration > Components > Contacts > New
Scroll down to Information.. that's what I'm trying to change. I'm trying to add "Region" in the list of values for the contact.

Based on the changes I made above the field shows there in the backend, saves fine and I get no errors, but the column doesn't show on the contacts page.

Re: adding fields to contacts component

Posted: Mon Sep 28, 2009 5:04 pm
by Per Yngve Berg
This thread is about the same hack with the users registration page http://forum.joomla.org/viewtopic.php?f=431&t=320643

Re: adding fields to contacts component

Posted: Wed Sep 30, 2009 3:52 pm
by goltoof
This is for managing users... way different. I just need more fields for the contacts.

Re: adding fields to contacts component

Posted: Mon Oct 26, 2009 10:07 pm
by alangeor
Hey goltoof, did you ever solve your problem? I'm trying to do the same thing.

Re: adding fields to contacts component

Posted: Wed Oct 28, 2009 11:08 pm
by goltoof
alangeor wrote:Hey goltoof, did you ever solve your problem? I'm trying to do the same thing.
Not yet.. been too busy with more important things. I suspect it has something to do with template overrides. Please let me know if you get anywhere, I'll do the same.

Re: adding fields to contacts component

Posted: Sat Jan 02, 2010 4:20 pm
by Wambat
I m hoping by bumping this thread that someone will come in and say that it has already been done.

All I want to do is add a COMPANY name to each contact. Yes, would seem like a very obvious need in my opinion too.
I tried QContacts as well. Cant see how to do it there either?

Regards to all,
Wambat

Re: adding fields to contacts component

Posted: Sun Jan 03, 2010 3:58 am
by unleash.it
Why hack com_contacts? An update will ruin your changes. If you really wanted you could duplicate it, but I'd think it's easier to use an extension and/or just create your own form.

Have you seen: http://extensions.joomla.org/extensions ... tails/4811

Also, the Contacts component is an example of something that a CCK extension could easily replace. I recommend Flexicontent: http://extensions.joomla.org/extensions ... tion/10667

Or Fabrik (a forms generator on steroids): http://extensions.joomla.org/extensions ... forms/1659

Re: adding fields to contacts component

Posted: Sun Jan 03, 2010 4:48 am
by Wambat
Thank you for taking the time to reply.
unleash.it wrote:Why hack com_contacts? An update will ruin your changes. If you really wanted you could duplicate it, but I'd think it's easier to use an extension and/or just create your own form.
Sure, I would rather use an extension, thus the reason I have tried your suggestion of QContact, which only has a way of adding fields to the email.... but there are none I can find that is as simple as com_contacts and have the required fields.

>Have you seen: http://extensions.joomla.org/extensions ... tails/4811[/quote]
>Also, the Contacts component is an example of something that a CCK extension could easily replace. I recommend Flexicontent: http://extensions.joomla.org/extensions ... tion/10667
>Or Fabrik (a forms generator on steroids): http://extensions.joomla.org/extensions ... forms/1659[/quote]

Both of these are GREAT components. I have experimented with them previously... but really.... all we need is just ONE extra little field. In my case, I see it as an omission not actually having the place for a company or employer name. Isn t that something you would need in a contact list?

I better go find out how to make a suggestion to the developers :-)

Re: adding fields to contacts component

Posted: Sun Jan 03, 2010 5:37 am
by unleash.it
Huh, I thought that Qcontacts could add some fields to the form. I admit I've never tried it though. Using the other extensions I mentioned always does it for me. It's really not hard at all. For the easiest possible though, you might just use Chronoforms. If you've ever done an HTML form, it couldn't be more simple. Just make a static form in Dreamweaver or your text editor with all the fields you like (and any layout or extra text) then paste into it. Then go to the validation tab an type in your field names. Or you could even use the built in wizard. Super simple.

Personally i almost think they should remove contacts from the core as it's something else to have to maintain. But I like having it around for simple sites that it's good enough on.

Oh after writing all that... I just thought of the obvious. Why not just rename say the fax number field? From the sound of your first post, it looks like you haven't discovered the difference between administrator/com_contacts and components/com_comcontacts. The latter deals with the front end. You would go there to change the label, or better yet, make a template override so updates won't erase it (search the documentation and you'll find your answer about overriddes).

Best of luck...

Edit: actually, even easier. The best place to change the label names is your language file. You could make an override if you want to change the layout or add more content. Look in the folder called laguages for the com_contacts.ini file.

Re: adding fields to contacts component

Posted: Tue Nov 02, 2010 2:54 am
by umponcel
I agree... Why make it so KISS (Keep It Simple and Stupid) when it can be more complicated (but more flexible)?

All we are looking for is the "How to" create a missing field in the beack-end and the front-end. I belive compagny is definitavly a missing field in todays needs. If it's not there, than let's doit!

More than 1 yeat this tread have been posted and no serious answers or no serious advancment have been posted.

Please help us to bring Joomla to another knowledge step one day.

Re: adding fields to contacts component

Posted: Tue Nov 02, 2010 10:38 am
by ooffick
ok, try the following:
  1. create a folder in your template folder called "html" (if it doesn't exists)
  2. create a folder in that html folder called "com_contact" (if it doesn't exists)
  3. create a folder in that com_contact folder called "contact" (if it doesn't exists)
  4. copy the file .../components/com_contact/views/contact/tmpl/default_form.php in this .../templates/[your-template]/html/com_contact/contact/ folder
  5. open that file
  6. find the following lines:

    Code: Select all

    			<br />
    			<label id="contact_emailmsg" for="contact_email">
    				&nbsp;<?php echo JText::_( 'Email address' );?>:
    			</label>
    			<br />
    			<input type="text" id="contact_email" name="email" size="30" value="" class="inputbox required validate-email" maxlength="100" />
  7. and replace it with the following:

    Code: Select all

    			<br />
    			<label id="contact_emailmsg" for="contact_email">
    				&nbsp;<?php echo JText::_( 'Email address' );?>:
    			</label>
    			<br />
    			<input type="text" id="contact_email" name="email" size="30" value="" class="inputbox required validate-email" maxlength="100" />
    
    			<br />
    			<label id="contact_phonemsg" for="contact_phone">
    				&nbsp;<?php echo JText::_( 'Phone' );?>:
    			</label>
    			<br />
    			<input type="text" id="contact_phone" name="phone" size="30" value="" class="inputbox" maxlength="100" />
    
    <br />
    			<label id="contact_companymsg" for="contact_company">
    				&nbsp;<?php echo JText::_( 'Company' );?>:
    			</label>
    			<br />
    			<input type="text" id="contact_company" name="company" size="30" value="" class="inputbox" maxlength="100" />
    
  8. save the file
  9. Set Components > Contacts > Contacts > Parameters > Custom Reply = Yes
  10. Install the following Contact Plugin
    plg_SubmitContact.zip
    which does the same as the normal one, except it adds the two fields to the email.
  11. Make sure the Plugin is enabled
Olaf

Re: adding fields to contacts component

Posted: Tue Nov 02, 2010 10:53 am
by umponcel
Thanks, but are you sure you understand what I'm trying to accomplish here? I'm not trying to change the contact form. I'm trying to change the administrative end of the Contacts component.

Re: adding fields to contacts component

Posted: Tue Nov 02, 2010 10:57 am
by ooffick
What part?

Re: adding fields to contacts component

Posted: Tue Nov 02, 2010 11:12 am
by umponcel
For clarification, go to Administration > Components > Contacts > New
Scroll down to Information. That's where and what I'm trying to change. I'm trying to add "Company Name" in the list of values for the contact.

Based on the changes we all made above (see first message of this post) the field shows there in the backend, system react and says he saves fine and returns no errors, but the column doesn't show on the contacts page (and the database) and when the contact is recalled, the company name doesn't appear.

Re: adding fields to contacts component

Posted: Tue Nov 02, 2010 11:37 am
by ooffick
ok, and did you change the mysql table as well, and hacked TableContact class as well?

Please note that I do not recommend to hack any Joomla Core files as this will make it extremely hard to upgrade to the next version.

Moreover, which Joomla version are you using?

Olaf

Re: adding fields to contacts component

Posted: Tue Nov 02, 2010 11:48 am
by umponcel
Yes I have done all the 5 steps indivated bellow. I'm i missing something?

Re: adding fields to contacts component

Posted: Tue Nov 02, 2010 11:50 am
by ooffick
Did you change the default_address.php file as well to add the new field to the frontend?

Re: adding fields to contacts component

Posted: Tue Nov 02, 2010 11:59 am
by umponcel
No! Where is this file?

Re: adding fields to contacts component

Posted: Tue Nov 02, 2010 12:00 pm
by ooffick
So you followed all the following steps:
  1. open the following file:/.../administrator/components/com_contact/tables/contact.php
  2. find the following code:

    Code: Select all

    	var $name 				= null;
    
  3. and replace it with the following:

    Code: Select all

    	var $name 				= null;
    	/** @var string */
    	var $company 				= null;
    
  4. open the following file:/.../administrator/components/com_contact/admin.contact.html.php
  5. find the following code:

    Code: Select all

    				<tr>
    					<td class="key">
    					<label for="con_position">
    						<?php echo JText::_( 'Contact\'s Position' ); ?>:
    						</label>
    					</td>
    					<td>
    						<input class="inputbox" type="text" name="con_position" id="con_position" size="60" maxlength="255" value="<?php echo $row->con_position; ?>" />
    					</td>
    				</tr>
    
  6. and replace it with the following:

    Code: Select all

    <tr>
    <td class="key" valign="top">
    <label for="Company">
    <?php echo JText::_( 'Company' ); ?>:
    </label>
    </td>
    <td>
    <input class="inputbox" type="text" name="company" id="company" size="60" maxlength="255" value="<?php echo $row->company; ?>" />
    </td>
    </tr>
    				<tr>
    					<td class="key">
    					<label for="con_position">
    						<?php echo JText::_( 'Contact\'s Position' ); ?>:
    						</label>
    					</td>
    					<td>
    						<input class="inputbox" type="text" name="con_position" id="con_position" size="60" maxlength="255" value="<?php echo $row->con_position; ?>" />
    					</td>
    				</tr>
    
  7. add the column with the name "company" to the database table "jos_contact_details"
  8. create a folder in your template folder called "html" (if it doesn't exists)
  9. create a folder in that html folder called "com_contact" (if it doesn't exists)
  10. create a folder in that com_contact folder called "contact" (if it doesn't exists)
  11. copy the file .../components/com_contact/views/contact/tmpl/default_address.php in this .../templates/[your-template]/html/com_contact/contact/ folder
  12. open that file
  13. find the following lines:

    Code: Select all

    defined( '_JEXEC' ) or die( 'Restricted access' );
    ?>
  14. and replace it with the following:

    Code: Select all

    defined( '_JEXEC' ) or die( 'Restricted access' );
    ?>
    <?php echo $this->escape($this->contact->company); ?>
    
  15. save the file
Olaf

Re: adding fields to contacts component

Posted: Wed Nov 03, 2010 6:50 pm
by umponcel
Sorry. I have follow all steps. the field compagny appear in the BE of the contact componant but doesn't save. in the Table in MySQL..

Re: adding fields to contacts component

Posted: Wed Nov 03, 2010 7:31 pm
by ooffick
And are you sure you have modified the correct Database table?

Olaf

Re: adding fields to contacts component

Posted: Wed Nov 03, 2010 10:49 pm
by umponcel
at 100%... I've follow your steps one by one ;-(

Re: adding fields to contacts component

Posted: Thu Nov 04, 2010 10:05 am
by ooffick
Which Joomla version do you have?

Olaf

Re: adding fields to contacts component

Posted: Thu Nov 04, 2010 11:22 am
by umponcel
1.5.20

Re: adding fields to contacts component

Posted: Thu Nov 04, 2010 12:13 pm
by ooffick
Can you tell me the what the columns in your jos_contact_details table look like?
Does it look like this:
capture#0350_2010-11-04.png
You might want to think about updating to Joomla! 1.5.21

Olaf

Re: adding fields to contacts component

Posted: Fri Nov 19, 2010 5:37 pm
by ninabarley
I've been doing the same thing. I'm running 1.5.22 and I had several fields I wanted to add to the admin side of the contact db, and be able to update in the back-end contacts page. On the front-end, I report on them using SQL 2 Excel.

So, part of this might help you, but I also have run into a question about saving all my updates as overrides.

I added the fields to the contact_details table, and then modified all of the following to add the new fields and their parameters:

Components/com_contact/views/contact/tmpl/default_address.php
Components/com_contact/views/contact/tmpl/default.php
* Components/com_contact/views/contact/view.html.php
Components/com_contact/views/category/tmpl/default_items.php
Components/com_contact/views/category/tmpl/default.php
*Components/com_contact/tables/contact.php
*Components/com_contact/controller.php
*administrator/components/com_contact/contact_items.xml
*administrator/components/com_contact/admin.contact.html.php

I've successfully added two fields and it's been working great, but now (when adding a third field) I can't remember how to save the files that aren't as deep as the tmpl directory (the ones with the *) without overriding the core code. Maybe I just hacked my core code last time and got lucky when I updated to 1.5.22
Is it possible to save them as overrides, and if so what directories do I put them into?

Re: adding fields to contacts component

Posted: Sun Nov 28, 2010 10:03 pm
by glimmerman72
I have followed these steps and added 3 fields, works great thank you.

ooffick wrote:So you followed all the following steps:
  1. open the following file:/.../administrator/components/com_contact/tables/contact.php
  2. find the following code:

    Code: Select all

    	var $name 				= null;
    
  3. and replace it with the following:

    Code: Select all

    	var $name 				= null;
    	/** @var string */
    	var $company 				= null;
    
  4. open the following file:/.../administrator/components/com_contact/admin.contact.html.php
  5. find the following code:

    Code: Select all

    				<tr>
    					<td class="key">
    					<label for="con_position">
    						<?php echo JText::_( 'Contact\'s Position' ); ?>:
    						</label>
    					</td>
    					<td>
    						<input class="inputbox" type="text" name="con_position" id="con_position" size="60" maxlength="255" value="<?php echo $row->con_position; ?>" />
    					</td>
    				</tr>
    
  6. and replace it with the following:

    Code: Select all

    <tr>
    <td class="key" valign="top">
    <label for="Company">
    <?php echo JText::_( 'Company' ); ?>:
    </label>
    </td>
    <td>
    <input class="inputbox" type="text" name="company" id="company" size="60" maxlength="255" value="<?php echo $row->company; ?>" />
    </td>
    </tr>
    				<tr>
    					<td class="key">
    					<label for="con_position">
    						<?php echo JText::_( 'Contact\'s Position' ); ?>:
    						</label>
    					</td>
    					<td>
    						<input class="inputbox" type="text" name="con_position" id="con_position" size="60" maxlength="255" value="<?php echo $row->con_position; ?>" />
    					</td>
    				</tr>
    
  7. add the column with the name "company" to the database table "jos_contact_details"
  8. create a folder in your template folder called "html" (if it doesn't exists)
  9. create a folder in that html folder called "com_contact" (if it doesn't exists)
  10. create a folder in that com_contact folder called "contact" (if it doesn't exists)
  11. copy the file .../components/com_contact/views/contact/tmpl/default_address.php in this .../templates/[your-template]/html/com_contact/contact/ folder
  12. open that file
  13. find the following lines:

    Code: Select all

    defined( '_JEXEC' ) or die( 'Restricted access' );
    ?>
  14. and replace it with the following:

    Code: Select all

    defined( '_JEXEC' ) or die( 'Restricted access' );
    ?>
    <?php echo $this->escape($this->contact->company); ?>
    
  15. save the file
Olaf