简体   繁体   中英

Add a custom field to joomla contact form

I'm trying to add a custom select field to the contact form. I'm editing the /components/com_contact/models/forms/contact.xml file and the fields are in the following format:

    <field name="contact_subject"
        type="text"
        id="contact-emailmsg"
        size="60"
        description="COM_CONTACT_CONTACT_MESSAGE_SUBJECT_DESC"
        label="COM_CONTACT_CONTACT_MESSAGE_SUBJECT_LABEL"
        filter="string"
        validate="contactemailsubject"
        required="true"
    />
    <field name="contact_message"
        type="textarea"
        cols="50"
        rows="10"
        id="contact-message"
        description="COM_CONTACT_CONTACT_ENTER_MESSAGE_DESC"
        label="COM_CONTACT_CONTACT_ENTER_MESSAGE_LABEL"
        filter="safehtml"
        validate="contactemailmessage"
        required="true"
    />
    <field name="contact_email_copy"
        type="checkbox"
        id="contact-email-copy"
        description="COM_CONTACT_CONTACT_EMAIL_A_COPY_DESC"
        label="COM_CONTACT_CONTACT_EMAIL_A_COPY_LABEL"
        default="0"
    />

My question is how to add a select type field as the default are only inputs, textarea and checkbox and couldn't find anything in the documentation

First thing : you really shouldn't go on hacking into a core component in that way. That is gross and highly dangerous, for you won't necessarily be able to guarantee that your website is still the same after any update. To my knowledge, there isn't any override method for forms as it exists for the view templates, so you'll end up with two choices :

1- find a custom component where you can configure your fields without tampering some code (like breezingforms for example). That would be my advise

2- copy the com_contact component into some com_personalized_contact, and then changing the code (Warning: every class name has to be changed, it can be pretty much).

As for how to write a select field: http://docs.joomla.org/List_form_field_type will answer all your questions

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