I will probably make this a plugin for myself, which is why I placed the JS file in the directory ‘media/plg_contactMoveFields’
I added to a template override of default_form in com_contact
->registerAndUseScript('plg_contactMoveFields.contactMoveFields', 'media/plg_contactMoveFields/js/contactMoveFields.js', [], ['defer' => 'true'], ["core", "jquery"]);
Then the contactMoveFields.js reads
jQuery(document).ready(function($) {
const formField = 'phone';
const placeAfter = 'email';
form = $('#contact-form');
moveField = form.find($('#jform_com_fields_' + formField)).parents('div.control-group');
removeFieldset = form.find('input[id="jform_com_fields_' + formField + '"]').parents('fieldset');
moveField.insertAfter(form.find('input[id="jform_contact_' + placeAfter + '"]').parents('div.control-group'));
removeFieldset.remove();
})
It works.
To view this discussion, visit https://groups.google.com/d/msgid/joomla-dev-general/b1904add-105c-47d4-a691-2c9465f47989n%40googlegroups.com.
Slightly better and more consistent JS
jQuery(document).ready(function($) {
const formField = 'phone';
const placeAfter = 'email';
form = $('#contact-form');
moveField = form.find('#jform_com_fields_' + formField).parents('div.control-group');
removeFieldset = form.find('#jform_com_fields_' + formField).parents('fieldset');
moveField.insertAfter(form.find('#jform_contact_' + placeAfter).parents('div.control-group'));
removeFieldset.remove();
})
Funny, I have been doing a lot with the contact component and form recently.
It is not sent because the contact component does not know about the field. You can use the custom fields to make a phone field. Make sure it is a “Mail” field not a contact field, and make sure you change the permissions so that editing the field is publicly allowed.
Make sure you say to show custom fields in the contact form.
The fields will come out Name, Email, Subject, Message, Phone. If you want it to be something like Name, Phone, Email, Subject, Message You can move the fields around with JavaScript. There was an earlier thread in this group on that which should help you do that.
To view this discussion, visit https://groups.google.com/d/msgid/joomla-dev-general/3995cde3-cfbf-410f-a120-88b34a2a7cben%40googlegroups.com.
Did you modify the mail template for the contact form?
From: joomla-de...@googlegroups.com <joomla-de...@googlegroups.com>
On Behalf Of Nico van de Kamp
Sent: Friday, February 14, 2025 03:07
To: Joomla! General Development <joomla-de...@googlegroups.com>
Subject: Re: [jgen] Contact form: how to add telephone number for the mailing?
Ok, I have changed it now, todo it by custom fields 'mail' for contact, with jQuery code is placed under e-mail field so that is the right position test side
But if I send this contact form, the telephone number is not send with the message.
Do I have to enable something at the custom field or at the contact?
To view this discussion, visit https://groups.google.com/d/msgid/joomla-dev-general/661883f5-435a-4bbd-870a-7160158b62e7n%40googlegroups.com.