How to tick "Send copy to yoursefl" by default? Topic is solved

General questions relating to Joomla! 3.x.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10
Locked
User avatar
bienthuy
Joomla! Apprentice
Joomla! Apprentice
Posts: 27
Joined: Wed Oct 08, 2014 6:45 am
Contact:

How to tick "Send copy to yoursefl" by default?

Post by bienthuy » Thu Nov 15, 2018 9:22 am

As title, in the com_contact form, there is an option call : "Send a copy to yourself"

I want this option will checked by default (current, it does not checked).
So, the question is, how can i make this option checked by default?

Image

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

Re: How to tick "Send copy to yoursefl" by default?

Post by SharkyKZ » Thu Nov 15, 2018 9:39 am

The proper way to alter forms is with a content plugin. The plugin would look like this:

Code: Select all

defined('_JEXEC') or die;

use Joomla\CMS\Form\Form;
use Joomla\CMS\Plugin\CMSPlugin;

class PlgContentExample extends CMSPlugin
{
	protected $app;

	public function onContentPrepareForm(Form $form, $data)
	{
			if (!$this->app->isClient('site') || $form->getName() !== 'com_contact.contact')
			{
				return true;
			}

			$form->setFieldAttribute('contact_email_copy', 'checked', 'true');

			return true;
	}
}
But because your change is cosmetic only (does not affect data filtering or validation), you can also use a template override. The file to override would be components/com_contact/views/contact/tmpl/default_form.php. In the override add this line:

Code: Select all

$this->form->setFieldAttribute('contact_email_copy', 'checked', 'true');

User avatar
bienthuy
Joomla! Apprentice
Joomla! Apprentice
Posts: 27
Joined: Wed Oct 08, 2014 6:45 am
Contact:

Re: How to tick "Send copy to yoursefl" by default?

Post by bienthuy » Thu Nov 15, 2018 9:56 am

Thank you so much, i used template overrides and it's working now.


Locked

Return to “General Questions/New to Joomla! 3.x”