Contact Form

These hooks let developers customize Contact Form in the Cost Calculator.

Important: Developers can use these hooks to customize only the default form.

ccb_contact_form_style_class

This hook allows to change classes of the form itself

Parameters:

  • $classes(String)

  • $settings(Array)

Example:

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:

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

This hook allows you to add HTML code to the submit button.

Parameters:

  • $settings(Array)

Example:

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:

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

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

Parameters:

  • $settings(Array)

Example:

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:


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

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

Example:

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:

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

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

Parameters:

  • $text(String)

Example:


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:

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:

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

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

Parameters:

  • $subject(String)

  • $calc_id(Integer)

Example:

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';
	}
}

Last updated