Having trouble with com_contact override Topic is solved

For Joomla! 3.x Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Post Reply
name7
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Wed Mar 01, 2017 9:51 pm

Having trouble with com_contact override

Post by name7 » Mon Oct 18, 2021 11:17 pm

The standard Contact form has an unnecessary message: "Send an email".

My goal is to remove that message.

Line 3 of root/components/com_contact/models/forms/contact.xml has this line:

Code: Select all

<fieldset name="contact" addrulepath="components/com_contact/models/rules" label="COM_CONTACT_CONTACT_DEFAULT_LABEL">
If you delete the label snippet, the goal is accomplished.

This is an obvious candidate for an override.

In the root/templates/mytemplate/html folder, I added a folder tree for com_contact/models/forms/
and I copied the contact.xml file into the forms folder and I made the necessary edit to the copied file.

It didn't work.
It works if I hack the core files, but it doesn't work if I use the override feature.

I saw a post from 2012 where a member here discovered that you have to truncate the file tree to make an override work as expected. I tried that. I eliminated the forms folder and then the models folder from the override file tree, but it still didn't work.

Does anyone here know how to make this work?

Thanks.
Last edited by toivo on Tue Oct 19, 2021 1:12 am, edited 1 time in total.
Reason: mod note: moved from 3.x General Questions

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2020
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: Having trouble with com_contact override

Post by SharkyKZ » Tue Oct 19, 2021 6:02 am

File overrides are for layouts only! Forms should be altered using plugins. But since this is only a cosmetic change, you can use a layout override. The file to override is components/com_contact/views/contact/tmpl/default_form.php.

Change this line:

Code: Select all

<?php if (isset($fieldset->label) && ($legend = trim(JText::_($fieldset->label))) !== '') : ?>
to this:

Code: Select all

<?php if ($fieldset->name !== 'contact' && isset($fieldset->label) && ($legend = trim(JText::_($fieldset->label))) !== '') : ?>
Another option is to create an override for the string.

name7
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Wed Mar 01, 2017 9:51 pm

Re: Having trouble with com_contact override

Post by name7 » Tue Oct 19, 2021 7:10 pm

Thanks Shark! I appreciate the tips.

This worked, but...

It only worked when I followed the 2011 tip from "forkless" in this thread: viewtopic.php?t=623000 .

As described in that post, I had to truncate the override filetree by removing the view folder and the tmpl folder from the equation.
So my override location is this:
templatename/html/com_contact/contact/default_form.php.

This counterintuitive aspect of override filetrees has apparently been around for a while. If I hadn't seen that old forkless post, I never would have succeeded in making this tiny change, but more importantly, I'd have lost faith in the override method because it didn't work.

Last question:
Now that I have a successful override in place, I have to ask about your suggested edit to L25:
Wouldn't it be simpler to just delete lines 25-27 in the override file, rather than editing L25 to cause the desired outcome?

I have no php skills. I'm not a coder. So my question isn't nitpicking, I'm just trying to learn a little more.

Thanks!

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2020
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: Having trouble with com_contact override

Post by SharkyKZ » Tue Oct 19, 2021 7:25 pm

There is plenty of documentation about overrides, including used paths:

https://docs.joomla.org/J3.x:Layout_Overrides_in_Joomla
https://docs.joomla.org/Understanding_Output_Overrides
https://docs.joomla.org/How_to_override ... omla!_core

Furthermore, you can use Template Manager to create overrides instead of having to manually copy and upload files using FTP https://docs.joomla.org/J3.x:How_to_use ... _Overrides.
Wouldn't it be simpler to just delete lines 25-27 in the override file, rather than editing L25 to cause the desired outcome?
Depends on your intentions. This would remove all fieldset legends. Additional fieldsets can be added by plugins. Omitting legends could lead to confusing UI if you have many fieldsets and is bad for accessibility.

name7
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Wed Mar 01, 2017 9:51 pm

Re: Having trouble with com_contact override

Post by name7 » Tue Oct 19, 2021 9:12 pm

OK! Thanks again for your detailed and informative replies! Very helpful!


Post Reply

Return to “Joomla! 3.x Coding”