简体   繁体   中英

Adding a custom field on Joomla 2.5 contact form

This maybe a question asked many times on Joomla forums, but after searching for some time, I did not find a good answer, instead of "its impossible" and "use a 3rd party form component". I want to add another field (phone number) on the default Joomla 2.5 contact form, so the user can send that info, along with his message. From what I've read, its said that is a Joomla limitation from his mail implementation, which can send only name, subject and message. I'm not a experienced Joomla developer, but from my limited knowledge, I belive this can be obtained in a simple way, just by adding fields in the template contact form and concatenate that fields with the message field (or at least that could solve my problem easily). Like I said, I'm not a experienced developer, so I can't figure out exactly how to do it (and preferably not breaking Joomla installation by modifying too much the core files, if thats the case). Anyone can help? Or at least point me in the right direction?

Thanks.

You're right, most people people say "use a 3rd party extension". However there is a very good reason for this. When using Joomla, it's not recommended to edit core files. "Why" you might ask. Purely because of the following reasons:

  1. They may get overridden in Joomla updates
  2. Joomla's coding style is very different to what people are used to and therefore old coding standards, some of which are considered insecure now, might get used as a lot of people don't read the Joomla documentation. A prime example would be people asking why retrieving data from the database using their code isn't working and they ahev using mysql_connect rather than the Joomla database class.
  3. The final reason is that if you're a little unsure what you're doing, any code you add may cause problems and results in faulty functionality with existing features. You just never know.

So to answer you're question (even though you may not want to hear this), I'm going to say use a 3rd party extension from this category:

http://extensions.joomla.org/extensions/contacts-and-feedback/contact-forms

There are a very big variety so simply see which one suits your needs.

Hope this gave you a good insight of things.

You should never edit core files in Joomla, otherwise an update to those files could potentially bring your site down. The following link will get you started creating a user plugin where you can add/remove all the fields you need.

http://docs.joomla.org/Creating_a_profile_plugin

Maybe a bit late and I hope you have solved your problem already.

But if not you can check out: Elin Warings tutorial for making a form plugin.

Or read about overrides for Joomla core functions: How to create a custom form field type.

您可以制作一个插件来添加字段,这并不难,也可以使用众多可用扩展之一。

If you want to add fields to contact us default form. You need to add fields in 4 files

1) /components/com_contact/controllers/contact.php`

            $phone      = $data['contact_phone'];

2) /components/com_contact/views/contact/tmpl/default_form.php

<dt><?php echo $this->form->getLabel('contact_phone'); ?></dt>
            <dd><?php echo $this->form->getInput('contact_phone'); ?></dd>

3) /components/com_contact/models/forms/contact.xml

<field name="contact_phone"
        type="phone"
        id="contact-phone"
        size="30"
        description="COM_CONTACT_PHONE_DESC"
        label="COM_CONTACT_PHONE_LABEL"
        filter="integer"
        required="false"
    />

4) templates/your template/html/com_contact/contact/default_form.php

<div>
 <?php echo $this->form->getLabel('contact_phone'); ?>
 <?php echo $this->form->getInput('contact_phone'); ?>

</div>

Thanks & Regards, Mithali

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM