How to add additional fields to contact form part of Cost Calculator?
If you like to add additional fields to contact form part of Cost Calculator, please do the following:
1. Open bt_cost_calculator.php file in the code editor.
2. Locate the following piece of code:
$output .= '<div class="btQuoteItem' . $m_message . ' btQuoteItemFullWidth"><textarea class="btContactMessage btContactField" placeholder="' . __( 'Message', 'bt-cost-calculator' ) . '"></textarea></div>';
and add above it the following:
$output .= '<div class="btQuoteItem"><input type="text" class="myText btContactField" placeholder="' . __( 'myText', 'bt-cost-calculator' ) . '"></div>';
This will create the new field in the form with the placeholder text myText. Change it according to your needs (edit placeholder="' . __( 'myText', 'bt_plugin' ) statement)
3. Locate the following piece of code in cc.main.js file:
'message' : c.find( '.btContactMessage' ).val()
and add above it the following:
'mytext' : c.find( '.myText' ).val(),
it will ensure that the value of the newly created field gets propagated to backend upon form submission
4. Locate the following piece of code in bt_cost_calculator.php file:
$message = $_POST['message'];
and add above it the following:
$mytext = $_POST['mytext'];
5. Locate the following piece of code in bt_cost_calculator.php file:
if ( $message != '' ) $message_to_admin .= '<div style="padding:.5em;"><b>' . __( 'Message', 'bt-cost-calculator' ) . '</b>: ' . stripslashes( $message ) . '</div>' . "\r\n";
and add above it the following:
if ( $mytext != '' ) $message_to_admin .= '<div style="padding:.5em;"><b>' . __( 'MyText', 'bt-cost-calculator' ) . '</b>: ' . $mytext . '</div>' . "\r\n";
It will include the value of your field into the email body.