Appearance
<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>
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
pageTitleKeyto hold translation key for page titlefieldscontaining option for fields used in contact formsubmitcontaining info for the submit buttonsenderEmailFieldto know which was the email of the sender (it points to afieldskey to allow more than one email fields in config and it can be null, if we don't have this in fields)frontTemplateViewholding the view key in front templatesemailTemplateViewholding the view key in email templates
Contact Form Fields
Each field can have the following keys
typecan be text, email, textarea, select, radio, checkbox, checkbox-group and uploadlabelKeythe translation key for the field's labelvalidationfor codeigniter validation rulesuploadif type is upload here are the needed options for uploader ['allowed_types' => 'pdf','size' => 2048]optionsif 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
selectit populates the dropdown - for type
radioit makes same field key based on field and uses options to make different radio value and label - for type
checkbox-groupit 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
- Added support for file attachments
- 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.
- There is a new key in
mainTemplate.jsonandTemplate.jsoncalledcontactFormGeneratedwhich has all the options that can be used in a mail from config - There is a new key in
emailViews.jsoncalledcontactEmailGeneratedto support thecontactFormGeneratedfrom front templates. It is an empty email displaying using foreach all elements from config
Contact form overrides
- if you have added fields in the default template the config must be updated to have theme in
fieldsoptions. - If you have changed the labels yu need to pass theme in the corresponding's field
labelKeyoption
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