# Contact Form

{% hint style="info" %}
Important: Developers can use these hooks to customize only the default form.
{% endhint %}

### **ccb\_contact\_form\_style\_class**&#x20;

This hook allows to change classes of the form itself

**Parameters:**

* **$classes(String)**
* **$settings(Array)**

**Example:**

```php
add_filter(ccb_contact_form_style_class, 'add_form_class', 10, 2);

function add_form_class($classes, $settings){ 
$classes .= ' my_class'; //replace my_class with the name of your class 

return $classes; 
}
```

### **ccb\_contact\_form\_submit\_class**

This hook allows you to change the classes of the form itself

**Parameters:**

* **$classes(String)**
* **$settings(Array)**

**Example:**

```php
add_filter(ccb_contact_form_submit_class, 'add_submit_button_class', 10, 2);

function add_submit_button_class($classes, $settings){
   if ( $settings['calc_id'] == 22 ) {
        $classes[] = 'my-custom-class';
    }
    return $classes;
}
```

### **ccb\_contact\_form\_submit\_action**&#x20;

This hook allows you to add HTML code to the submit button.&#x20;

**Parameters**:

* **$settings(Array)**

**Example:**

```php
add_action('ccb_contact_form_submit_action', 'your_function_name');
function your_function_name($settings){
  if($settings['calc_id'] == 240){ //change 240 to your calculator ID!
    echo 'custom html code';
  }
}
```

### **ccb\_contact\_form\_add\_fields**

This hook adds additional fields to the contact form, when adding an additional field you need to add two hooks **ccb\_contact\_form\_add\_requires**, **ccb\_contact\_form\_add\_text\_form\_fields** and **ccb\_contact\_form\_add\_sendform\_fields** as these parts are mandatory when adding new fields, otherwise when submitting the form an empty value will be passed to the back part.

**Parameters**:

* **$settings(Array)**

**Example:**

```php
add_action('ccb_contact_form_add_fields', 'maby_add_fields', 10, 1);

function maby_add_fields() {
    echo '<div class="calc-item ccb-field ccb-field-quantity" :class="{required: getRequiredMessage(\'new_message\')}">
        <span :class="{active: getRequiredMessage(\'new_message\')}" class="ccb-error-tip front default" v-text="getRequiredMessage(\'new_message\')"></span>
        <div class="calc-item__title">
            <span>Custom field title</span>
            <span class="ccb-required-mark">*</span>
        </div>
        <div class="calc-input-wrapper ccb-field">
            <input v-if="sendFields[4]" type="number" :disabled="loader" v-model="sendFields[4].value" @input="clearRequired(\'new_message\')" class="calc-input ccb-field ccb-appearance-field">
        </div>
    </div>';
}
```

### **ccb\_contact\_form\_add\_requires**&#x20;

This is a hook to add values for fields if the field is mandatory

**Parameters:**

* **$settings(Array)**

**Example:**

```php
add_filter('ccb_contact_form_add_requires', 'add_sendform_requires', 10, 1);

function add_sendform_requires($requires){
	$newRequires = array(
		'required' => true 
	);
	array_push($requires, $newRequires);

	return $requires;
}
```

### **ccb\_contact\_form\_add\_text\_form\_fields**

This is a hook to add text values that are warnings in case the user has not filled in the required fields.

**Parameters:**

* **$settings(Array)**

**Example:**

```php

add_filter('ccb_contact_form_add_text_form_fields', 'add_sendform_required_text_fields', 10, 1);

function add_sendform_required_text_fields($textMessages){
$textMessages['new_message'] = 'New message is required to be filled.'; 
return $textMessages;
}
```

### **ccb\_contact\_form\_submit\_label**&#x20;

This is a hook that allows you to change the text of the submit button individually and globally.

**Example:**

```php
function change_submitbtn_label($button_text, $calc_id){
	if($calc_id == 252){
		$button_text = 'Submit Form';
	}

	return $button_text;
}
```

### **ccb\_contact\_form\_add\_sendform\_fields**

This is the structure of all fields before submitting to the back end, and is a required part before submitting.

**Parameters:**

* **$settings(Array)**

**Example:**

```php
add_filter('ccb_contact_form_add_sendform_fields', 'add_sendform_fields_to_front', 10, 1);

function add_sendform_fields_to_front($sendformFields){
	$newFields = array('name'=> 'new_message', 'required' => true, 'value' => '');
	array_push($sendformFields, $newFields);
	return $sendformFields;
}
```

### **ccb\_contact\_form\_invalid\_error**&#x20;

This hook allows you to change the error text when submitting a form

**Parameters:**

* **$text(String)**

**Example:**

```php

add_filter('ccb_contact_form_invalid_error', 'change_form_error_message');

function change_form_error_message(){
	return 'Custom error message';
}
```

### **ccb\_contact\_form\_general\_add\_email\_fields**

Add additional fields to receive email notifications in the main calculator settings.

**Example:**

```php
add_action('ccb_contact_form_general_add_email_fields', 'add_receiver_email_fields');

function add_receiver_email_fields(){
	echo '
    <div class="col col-3" v-for="(email, index) in generalSettings.form_fields.customEmailAddresses" :key="index">
      <div class="ccb-input-wrapper">
        <span class="ccb-input-label">Custom email</span>
        <input
          type="email"
          v-model="generalSettings.form_fields.customEmailAddresses[index]"
          placeholder="Enter your custom email"
          autocomplete="off"
        >
        <button @click="removeEmail(index)">Remove</button>
      </div>
    </div>
    <button @click="addEmail">Add Email</button>
  </div>';
}
```

### **ccb\_contact\_form\_settings\_add\_email\_fields**

This hook allows you to add recipients through individual calculator settings.

**Example:**

```php
add_action('ccb_contact_form_settings_add_email_fields', 'add_form_receiver_email_fields');

function add_form_receiver_email_fields(){
	echo '
    <div class="col col-3" v-for="(email, index) in settingsField.formFields.customEmailAddresses" :key="index">
      <div class="ccb-input-wrapper">
        <span class="ccb-input-label">Custom email</span>
        <input
          type="email"
          v-model="settingsField.formFields.customEmailAddresses[index]"
          placeholder="Enter your custom email"
          autocomplete="off"
        >
        <button @click="removeEmail(index)">Remove</button>
      </div>
    </div>
    <button @click="addEmail">Add Email</button>
  </div>';
}
```

### **ccb\_email\_subject**&#x20;

This is a hook to change the subject of an email when sending a calculator form.

**Parameters:**

* **$subject(String)**
* **$calc\_id(Integer)**

**Example:**

```php
add_filter('cbb_email_subject', 'change_email_subject', 10, 2);

function change_email_subject($subject, $calc_id){
	if($calc_id == 257){
		return 'changed_subject_demo_257';
	}
}
```
