Skip to content

<div style="display: none;" hidden="true" aria-hidden="true">Are you an LLM? You can read better optimized documentation at /guides/ContactFormsFromConfig.md for this page in Markdown format</div>

Home | Changelog

Contact Forms From Config

Config

In application/config/contact_forms.php we hold config for form contacts.

Contact form keys

It has contact form keys

php
$config['contactForms'] = [
    'contactForm' => [...],
    'fullSampleForm' => [...],
]

to hold options to generate a contact form that supports attachments

Contact Form Options

Each contact form key has

  • pageTitleKey to hold translation key for page title
  • fields containing option for fields used in contact form
  • submit containing info for the submit button
  • senderEmailField to know which was the email of the sender (it points to a fields key to allow more than one email fields in config and it can be null, if we don't have this in fields)
  • frontTemplateView holding the view key in front templates
  • emailTemplateView holding the view key in email templates

Contact Form Fields

Each field can have the following keys

  • type can be text, email, textarea, select, radio, checkbox, checkbox-group and upload
  • labelKey the translation key for the field's label
  • validation for codeigniter validation rules
  • upload if type is upload here are the needed options for uploader ['allowed_types' => 'pdf','size' => 2048]
  • options if type is select, radio or checkbox-group it has options to pass to elements ['option1' => 'key.option1', 'option2' => 'key.option2']

Notes

  • validation is not required to exist as key. If an upload needs to be required add validation = 'required'
  • upload will be used only for field of type upload
  • for type select it populates the dropdown
  • for type radio it makes same field key based on field and uses options to make different radio value and label
  • for type checkbox-group it makes inputs checkboxes with name being the option's key and label the option's value

Full Sample Form Config

fullSampleForm contains all types that can be used to generate a contact form

php
'fullSampleForm' => [
    'pageTitleKey' => 'contactForm.fullSampleForm.pageTitle',
    'fields' => [
        'name' => [
            'type' => 'text',
            'labelKey' => 'contactForm.fullSampleForm.label.name',
            'validation' => 'trim|required'
        ],
        'surname' => [
            'type' => 'text',
            'labelKey' => 'contactForm.fullSampleForm.label.surname',
            'validation' => 'trim|required'
        ],
        'telephone' => [
            'type' => 'text',
            'labelKey' => 'contactForm.fullSampleForm.label.phone',
            'validation' => 'trim'
        ],
        'email' => [
            'type' => 'email',
            'labelKey' => 'contactForm.fullSampleForm.label.mail',
            'validation' => 'trim|required|valid_email'
        ],
        'pdf' => [
            'type' => 'upload',
            'labelKey' => 'contactForm.fullSampleForm.label.pdf',
            'validation' => 'required',
            'upload' => [
                'allowed_types' => 'pdf',
                'size' => 2048
            ]
        ],
        'image' => [
            'type' => 'upload',
            'labelKey' => 'contactForm.fullSampleForm.label.image',
            'upload' => [
                'allowed_types' => 'png|jpg|jpeg',
                'size' => 2048
            ]
        ],
        'department' => [
            'type' => 'select',
            'labelKey' => 'contactForm.fullSampleForm.label.department',
            'validation' => 'required',
            'options' => [
                'hr' => 'contactForm.fullSampleForm.label.department.hr',
                'marketing' => 'contactForm.fullSampleForm.label.department.marketing',
                'development' => 'contactForm.fullSampleForm.label.department.development',
            ]
        ],
        'active' => [
            'type' => 'checkbox',
            'labelKey' => 'contactForm.fullSampleForm.label.active',
            'validation' => ''
        ],
        'satisfaction' => [
            'type' => 'radio',
            'labelKey' => 'contactForm.fullSampleForm.label.satisfaction',
            'validation' => 'required',
            'options' => [
                'high' => 'contactForm.fullSampleForm.label.satisfaction.high',
                'medium' => 'contactForm.fullSampleForm.label.satisfaction.medium',
                'low' => 'contactForm.fullSampleForm.label.satisfaction.low',
            ]
        ],
        'requestFor' => [
            'type' => 'checkbox-group',
            'labelKey' => 'contactForm.fullSampleForm.label.requestFor',
            'validation' => '',
            'options' => [
                'option1' => 'contactForm.fullSampleForm.label.requestFor.option1',
                'option2' => 'contactForm.fullSampleForm.label.requestFor.option2',
                'option3' => 'contactForm.fullSampleForm.label.requestFor.option3',
            ]
        ],
        'message' => [
            'type' => 'textarea',
            'labelKey' => 'contactForm.fullSampleForm.label.message',
            'validation' => 'trim|required'
        ]
    ],
    'submit' => [
        'name' => 'submit',
        'labelKey' => 'contactForm.fullSampleForm.label.submit'
    ],
    'senderEmailField' => 'email',
    'frontTemplateView' => 'contactFormGenerated',
    'emailTemplateView' => 'contactEmailGenerated'
]

Contact Form Changes

  1. Added support for file attachments
  2. We have not changed the views of default and main template for contactForm. Adv_forms controller reads config but views and email views are kept as is.
  3. There is a new key in mainTemplate.json and Template.json called contactFormGenerated which has all the options that can be used in a mail from config
  4. There is a new key in emailViews.json called contactEmailGenerated to support the contactFormGenerated from front templates. It is an empty email displaying using foreach all elements from config

Contact form overrides

  1. if you have added fields in the default template the config must be updated to have theme in fields options.
  2. If you have changed the labels yu need to pass theme in the corresponding's field labelKey option

Additional contact forms

Adv_form::contactForm takes as argument the contactForm key. So for a new contact form ie askUsEmail you need to create the config for it. The front view can be kept as is if there is already one, otherwise you can create one based on the contactFormGenerated view