Untitled

 avatar
unknown
plain_text
a year ago
7.3 kB
5
Indexable

function handle_dealer_form() {
    // Check the nonce
    check_ajax_referer('dealer_form_nonce', 'nonce');

    // Parse the serialized form data
    parse_str($_POST['form'], $form_data);

    // Sanitize and validate form data
    $title = sanitize_text_field($form_data['title']);
    $company_name = sanitize_text_field($form_data['company_name']);
    $phone = sanitize_text_field($form_data['phone']);
    $email = sanitize_email($form_data['email']);
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        wp_send_json_error('Invalid email format');
    }
    $registered_company = sanitize_text_field($form_data['registered_company']);
    $date_business_commenced = sanitize_text_field($form_data['date_business_commenced']);
    $business_type = sanitize_text_field($form_data['business_type']);
    $business_location = sanitize_text_field($form_data['business_location']);
    $location_duration = sanitize_text_field($form_data['location_duration']);
    $account_payable_contact = sanitize_text_field($form_data['account_payable_contact']);
    $account_payable_phone = sanitize_text_field($form_data['account_payable_phone']);
    $account_payable_email = sanitize_email($form_data['account_payable_email']);
    if (!filter_var($account_payable_email, FILTER_VALIDATE_EMAIL)) {
        wp_send_json_error('Invalid account payable email format');
    }
    $bank_name = sanitize_text_field($form_data['bank_name']);
    $bank_address = sanitize_text_field($form_data['bank_address']);
    $bank_phone = sanitize_text_field($form_data['bank_phone']);
    $account_number = sanitize_text_field($form_data['account_number']);
    $account_type = sanitize_text_field($form_data['account_type']);
    $gst = sanitize_text_field($form_data['gst']);
    $pst = sanitize_text_field($form_data['pst']);
    $reference_company_1 = sanitize_text_field($form_data['reference_company_1']);
    $reference_contact_1 = sanitize_text_field($form_data['reference_contact_1']);
    $reference_address_1 = sanitize_text_field($form_data['reference_address_1']);
    $reference_phone_1 = sanitize_text_field($form_data['reference_phone_1']);
    $reference_city_prov_postal_1 = sanitize_text_field($form_data['reference_city_prov_postal_1']);
    $reference_email_1 = sanitize_email($form_data['reference_email_1']);
    if (!filter_var($reference_email_1, FILTER_VALIDATE_EMAIL)) {
        wp_send_json_error('Invalid reference email 1 format');
    }
    $reference_terms_1 = sanitize_text_field($form_data['reference_terms_1']);
    $reference_credit_limit_1 = sanitize_text_field($form_data['reference_credit_limit_1']);
    $reference_company_2 = sanitize_text_field($form_data['reference_company_2']);
    $reference_contact_2 = sanitize_text_field($form_data['reference_contact_2']);
    $reference_address_2 = sanitize_text_field($form_data['reference_address_2']);
    $reference_phone_2 = sanitize_text_field($form_data['reference_phone_2']);
    $reference_city_prov_postal_2 = sanitize_text_field($form_data['reference_city_prov_postal_2']);
    $reference_email_2 = sanitize_email($form_data['reference_email_2']);
    if (!filter_var($reference_email_2, FILTER_VALIDATE_EMAIL)) {
        wp_send_json_error('Invalid reference email 2 format');
    }
    $reference_terms_2 = sanitize_text_field($form_data['reference_terms_2']);
    $reference_credit_limit_2 = sanitize_text_field($form_data['reference_credit_limit_2']);
    $signature_1 = sanitize_text_field($form_data['signature_1']);
    $name_title_1 = sanitize_text_field($form_data['name_title_1']);
    $date_1 = sanitize_text_field($form_data['date_1']);
    $signature_2 = sanitize_text_field($form_data['signature_2']);
    $name_title_2 = sanitize_text_field($form_data['name_title_2']);
    $date_2 = sanitize_text_field($form_data['date_2']);

    // Format the message
    $message = "
    <html>
    <head>
        <title>New Credit Application Form Submission</title>
    </head>
    <body>
        <h2>Business Contact Information</h2>
        <p><strong>Title:</strong> $title</p>
		<p><strong>Company Name:</strong> $company_name</p>
        <p><strong>Phone:</strong> $phone</p>
        <p><strong>Email:</strong> $email</p>
        <p><strong>Registered Company Address:</strong> $registered_company</p>
        <p><strong>Date Business Commenced:</strong> $date_business_commenced</p>
        <p><strong>Business Type:</strong> $business_type</p>

        <h2>Business and Credit Information</h2>
        <p><strong>Business Location Address:</strong> $business_location</p>
        <p><strong>How long at current address?</strong> $location_duration</p>
        <p><strong>Account Payable Contact Name:</strong> $account_payable_contact</p>
        <p><strong>Account Payable Phone Number:</strong> $account_payable_phone</p>
        <p><strong>Account Payable E-mail:</strong> $account_payable_email</p>
        <p><strong>Bank Name:</strong> $bank_name</p>
        <p><strong>Bank Address:</strong> $bank_address</p>
        <p><strong>Bank Phone:</strong> $bank_phone</p>
        <p><strong>Account Number:</strong> $account_number</p>
        <p><strong>Type of Account:</strong> $account_type</p>
        <p><strong>GST #:</strong> $gst</p>
        <p><strong>PST #:</strong> $pst</p>

        <h2>Business/Trade References</h2>
        <p><strong>Company Name:</strong> $reference_company_1</p>
        <p><strong>Contact Name:</strong> $reference_contact_1</p>
        <p><strong>Address:</strong> $reference_address_1</p>
        <p><strong>Phone Number:</strong> $reference_phone_1</p>
        <p><strong>City, Prov and Postal Code:</strong> $reference_city_prov_postal_1</p>
        <p><strong>E-mail:</strong> $reference_email_1</p>
        <p><strong>Terms:</strong> $reference_terms_1</p>
        <p><strong>Credit Limit:</strong> $reference_credit_limit_1</p>
        <p><strong>Company Name:</strong> $reference_company_2</p>
        <p><strong>Contact Name:</strong> $reference_contact_2</p>
        <p><strong>Address:</strong> $reference_address_2</p>
        <p><strong>Phone Number:</strong> $reference_phone_2</p>
        <p><strong>City, Prov and Postal Code:</strong> $reference_city_prov_postal_2</p>
        <p><strong>E-mail:</strong> $reference_email_2</p>
        <p><strong>Terms:</strong> $reference_terms_2</p>
        <p><strong>Credit Limit:</strong> $reference_credit_limit_2</p>

        <h2>Signatures</h2>
        <p><strong>Signature:</strong> $signature_1</p>
        <p><strong>Name and Title:</strong> $name_title_1</p>
        <p><strong>Date:</strong> $date_1</p>
        <p><strong>Signature:</strong> $signature_2</p>
        <p><strong>Name and Title:</strong> $name_title_2</p>
        <p><strong>Date:</strong> $date_2</p>
    </body>
    </html>
    ";

    // Set content-type header for HTML email
    $headers = array('Content-Type: text/html; charset=UTF-8');

    // Send email
    if (wp_mail('ashkan.rahnavardi@gmail.com', 'New Credit Application Form Submission', $message, $headers)) {
        wp_send_json_success('Email sent successfully.');
    } else {
        wp_send_json_error('Failed to send email.');
    }
}
add_action('wp_ajax_handle_dealer_form', 'handle_dealer_form');
add_action('wp_ajax_nopriv_handle_dealer_form', 'handle_dealer_form');
Editor is loading...
Leave a Comment