A child theme is required to properly implement this customization. If you are not currently using a child theme, you can download one using the following link:
https://www.dropbox.com/s/ut4dkjq5n7j9nkz/divi-child-theme-0.1.1.r20.zip?dl=1
Add the first code snippet (below) to your child theme’s functions.php. Then add the second one to a new file in your child theme’s directory named my-main-modules.php.
shortcode_atts[‘module_id’];
$module_class = $this->shortcode_atts[‘module_class’];
$captcha = $this->shortcode_atts[‘captcha’];
$email = $this->shortcode_atts[’email’];
$title = $this->shortcode_atts[‘title’];
$form_background_color = $this->shortcode_atts[‘form_background_color’];
$input_border_radius = $this->shortcode_atts[‘input_border_radius’];
$button_custom = $this->shortcode_atts[‘custom_button’];
$custom_icon = $this->shortcode_atts[‘button_icon’];
$custom_message = $this->shortcode_atts[‘custom_message’];
$use_redirect = $this->shortcode_atts[‘use_redirect’];
$redirect_url = $this->shortcode_atts[‘redirect_url’];
$success_message = $this->shortcode_atts[‘success_message’];
global $et_pb_contact_form_num;
$module_class = ET_Builder_Element::add_module_order_class( $module_class, $function_name );
if ( ” !== $form_background_color ) {
ET_Builder_Element::set_style( $function_name, array(
‘selector’ => ‘%%order_class%% .input’,
‘declaration’ => sprintf(
‘background-color: %1$s;’,
esc_html( $form_background_color )
),
) );
}
if ( ! in_array( $input_border_radius, array( ”, ‘0’ ) ) ) {
ET_Builder_Element::set_style( $function_name, array(
‘selector’ => ‘%%order_class%% .input’,
‘declaration’ => sprintf(
‘-moz-border-radius: %1$s; -webkit-border-radius: %1$s; border-radius: %1$s;’,
esc_html( et_builder_process_range_value( $input_border_radius ) )
),
) );
}
$success_message = ” !== $success_message ? $success_message : esc_html__( ‘Thanks for contacting us’, ‘et_builder’ );
$et_pb_contact_form_num = $this->shortcode_callback_num();
$content = $this->shortcode_content;
$et_error_message = ”;
$et_contact_error = false;
$current_form_fields = isset( $_POST[‘et_pb_contact_email_fields_’ . $et_pb_contact_form_num] ) ? $_POST[‘et_pb_contact_email_fields_’ . $et_pb_contact_form_num] : ”;
$contact_email = ”;
$processed_fields_values = array();
$nonce_result = isset( $_POST[‘_wpnonce-et-pb-contact-form-submitted’] ) && wp_verify_nonce( $_POST[‘_wpnonce-et-pb-contact-form-submitted’], ‘et-pb-contact-form-submit’ ) ? true : false;
// check that the form was submitted and et_pb_contactform_validate field is empty to protect from spam
if ( $nonce_result && isset( $_POST[‘et_pb_contactform_submit_’ . $et_pb_contact_form_num] ) && empty( $_POST[‘et_pb_contactform_validate_’ . $et_pb_contact_form_num] ) ) {
if ( ” !== $current_form_fields ) {
$fields_data_json = str_replace( ‘\\’, ” , $current_form_fields );
$fields_data_array = json_decode( $fields_data_json, true );
// check whether captcha field is not empty
if ( ‘on’ === $captcha && ( ! isset( $_POST[‘et_pb_contact_captcha_’ . $et_pb_contact_form_num] ) || empty( $_POST[‘et_pb_contact_captcha_’ . $et_pb_contact_form_num] ) ) ) {
$et_error_message .= sprintf( ‘
%1$s
‘, esc_html__( ‘Make sure you entered the captcha.’, ‘et_builder’ ) );
$et_contact_error = true;
}
// check all fields on current form and generate error message if needed
if ( ! empty( $fields_data_array ) ) {
foreach( $fields_data_array as $index => $value ) {
// check all the required fields, generate error message if required field is empty
if ( ‘required’ === $value[‘required_mark’] && empty( $_POST[ $value[‘field_id’] ] ) ) {
$et_error_message .= sprintf( ‘
%1$s
‘, esc_html__( ‘Make sure you fill in all required fields.’, ‘et_builder’ ) );
$et_contact_error = true;
continue;
}
// additional check for email field
if ( ’email’ === $value[‘field_type’] && ! empty( $_POST[ $value[‘field_id’] ] ) ) {
$contact_email = sanitize_email( $_POST[ $value[‘field_id’] ] );
if ( ! is_email( $contact_email ) ) {
$et_error_message .= sprintf( ‘
%1$s
‘, esc_html__( ‘Invalid Email.’, ‘et_builder’ ) );
$et_contact_error = true;
}
}
// prepare the array of processed field values in convenient format
if ( false === $et_contact_error ) {
$processed_fields_values[ $value[‘original_id’] ][‘value’] = isset( $_POST[ $value[‘field_id’] ] ) ? $_POST[ $value[‘field_id’] ] : ”;
$processed_fields_values[ $value[‘original_id’] ][‘label’] = $value[‘field_label’];
}
}
}
} else {
$et_error_message .= sprintf( ‘
%1$s
‘, esc_html__( ‘Make sure you fill in all required fields.’, ‘et_builder’ ) );
$et_contact_error = true;
}
} else {
if ( false === $nonce_result && isset( $_POST[‘et_pb_contactform_submit_’ . $et_pb_contact_form_num] ) && empty( $_POST[‘et_pb_contactform_validate_’ . $et_pb_contact_form_num] ) ) {
$et_error_message .= sprintf( ‘
%1$s
‘, esc_html__( ‘Please refresh the page and try again.’, ‘et_builder’ ) );
}
$et_contact_error = true;
}
// generate digits for captcha
$et_pb_first_digit = rand( 1, 15 );
$et_pb_second_digit = rand( 1, 15 );
if ( ! $et_contact_error && $nonce_result ) {
$et_email_to = ” !== $email
? $email
: get_site_option( ‘admin_email’ );
$et_site_name = get_option( ‘blogname’ );
$contact_name = isset( $processed_fields_values[‘name’] ) ? stripslashes( sanitize_text_field( $processed_fields_values[‘name’][‘value’] ) ) : ”;
if ( ” !== $custom_message ) {
$message_pattern = $custom_message;
// insert the data from contact form into the message pattern
foreach ( $processed_fields_values as $key => $value ) {
$message_pattern = str_ireplace( “%%{$key}%%”, $value[‘value’], $message_pattern );
}
} else {
// use default message pattern if custom pattern is not defined
$message_pattern = isset( $processed_fields_values[‘message’][‘value’] ) ? $processed_fields_values[‘message’][‘value’] : ”;
// Add all custom fields into the message body by default
foreach ( $processed_fields_values as $key => $value ) {
if ( ! in_array( $key, array( ‘message’, ‘name’, ’email’ ) ) ) {
$message_pattern .= “\r\n”;
$message_pattern .= sprintf(
‘%1$s: %2$s’,
” !== $value[‘label’] ? $value[‘label’] : $key,
$value[‘value’]
);
}
}
}
$headers[] = “From: \”{$contact_name}\” <{$contact_email}>“;
$headers[] = “Reply-To: <{$contact_email}>“;
wp_mail( apply_filters( ‘et_contact_page_email_to’, $et_email_to ),
et_get_safe_localization( sprintf(
__( ‘New Message From %1$s%2$s’, ‘et_builder’ ),
sanitize_text_field( html_entity_decode( $et_site_name ) ),
( ” !== $title ? et_get_safe_localization( sprintf( _x( ‘ – %s’, ‘contact form title separator’, ‘et_builder’ ), sanitize_text_field( html_entity_decode( $title ) ) ) ) : ” )
) ),
stripslashes( wp_strip_all_tags( $message_pattern ) ), apply_filters( ‘et_contact_page_headers’, $headers, $contact_name, $contact_email ) );
$et_error_message = sprintf( ‘
%1$s
‘, esc_html( $success_message ) );
}
$form = ”;
$et_pb_captcha = sprintf( ‘
%1$s =
‘,
sprintf( ‘%1$s + %2$s’, esc_html( $et_pb_first_digit ), esc_html( $et_pb_second_digit ) ),
esc_attr( $et_pb_contact_form_num ),
esc_attr( $et_pb_first_digit ),
esc_attr( $et_pb_second_digit )
);
if ( ” === trim( $content ) ) {
$content = do_shortcode( $this->predefined_child_modules() );
}
if ( $et_contact_error ) {
$form = sprintf( ‘
‘,
esc_url( get_permalink( get_the_ID() ) ),
( ‘on’ === $captcha ? $et_pb_captcha : ” ),
$this->submit_button_text,
wp_nonce_field( ‘et-pb-contact-form-submit’, ‘_wpnonce-et-pb-contact-form-submitted’, true, false ),
” !== $custom_icon && ‘on’ === $button_custom ? sprintf(
‘ data-icon=”%1$s”‘,
esc_attr( et_pb_process_font_icon( $custom_icon ) )
) : ”,
” !== $custom_icon && ‘on’ === $button_custom ? ‘ et_pb_custom_button_icon’ : ”,
esc_attr( $et_pb_contact_form_num ),
$content
);
}
$output = sprintf( ‘
%3$s
‘,
( ” !== $title ? sprintf( ‘
%1$s
‘, esc_html( $title ) ) : ” ),
” !== $et_error_message ? $et_error_message : ”,
$form,
( ” !== $module_id
? esc_attr( $module_id )
: esc_attr( ‘et_pb_contact_form_’ . $et_pb_contact_form_num )
),
( ” !== $module_class ? sprintf( ‘ %1$s’, esc_attr( $module_class ) ) : ” ),
esc_attr( $et_pb_contact_form_num ),
‘on’ === $use_redirect && ” !== $redirect_url ? sprintf( ‘ data-redirect_url=”%1$s”‘, esc_attr( $redirect_url ) ) : ”
);
return $output;
}
}
Recent Comments