{"id":3626,"date":"2024-11-11T21:12:23","date_gmt":"2024-11-11T21:12:23","guid":{"rendered":"https:\/\/admytelecom.com\/?page_id=3626"},"modified":"2024-11-16T07:00:49","modified_gmt":"2024-11-16T07:00:49","slug":"home-improvement-form","status":"publish","type":"page","link":"https:\/\/admytelecom.com\/index.php\/home-improvement-form\/","title":{"rendered":"Home Improvement Form"},"content":{"rendered":"\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>Lead Form<\/title>\n<\/head>\n<body>\n    <form id=\"leadForm\">\n        <label for=\"campaign_id\">Campaign ID:<\/label>\n        <select id=\"campaign_id\" name=\"campaign_id\" required onchange=\"updateFormFields()\">\n            <option value=\"\">Select Campaign ID<\/option>\n            <option value=\"3589\">3589<\/option>\n            <option value=\"3590\">3590<\/option>\n            <option value=\"3591\">3591<\/option>\n            <option value=\"3592\">3592<\/option>\n            <option value=\"3593\">3593<\/option>\n        <\/select><br>\n\n        <label for=\"first_name\">First Name:<\/label>\n        <input type=\"text\" id=\"first_name\" name=\"first_name\" required><br>\n\n        <label for=\"last_name\">Last Name:<\/label>\n        <input type=\"text\" id=\"last_name\" name=\"last_name\" required><br>\n\n        <label for=\"phone_home\">Phone Home:<\/label>\n        <input type=\"text\" id=\"phone_home\" name=\"phone_home\" required><br>\n\n        <label for=\"email_address\">Email Address:<\/label>\n        <input type=\"email\" id=\"email_address\" name=\"email_address\" required><br>\n\n        <label for=\"address\">Address:<\/label>\n        <input type=\"text\" id=\"address\" name=\"address\" required><br>\n\n        <label for=\"city\">City:<\/label>\n        <input type=\"text\" id=\"city\" name=\"city\" required><br>\n\n        <label for=\"state\">State:<\/label>\n        <input type=\"text\" id=\"state\" name=\"state\" required><br>\n\n        <label for=\"zip_code\">Zip Code:<\/label>\n        <input type=\"text\" id=\"zip_code\" name=\"zip_code\" required><br>\n\n        <div id=\"additionalFields\">\n            <label for=\"utility_provider\" class=\"optional\" style=\"display:none\">Utility Provider:<\/label>\n            <input type=\"text\" id=\"utility_provider\" name=\"utility_provider\" class=\"optional\" style=\"display:none\"><br>\n\n            <label for=\"roof_shade\" class=\"optional\" style=\"display:none\">Roof Shade:<\/label>\n            <input type=\"text\" id=\"roof_shade\" name=\"roof_shade\" class=\"optional\" style=\"display:none\"><br>\n\n            <label for=\"utility_bill_amount\" class=\"optional\" style=\"display:none\">Utility Bill Amount:<\/label>\n            <input type=\"text\" id=\"utility_bill_amount\" name=\"utility_bill_amount\" class=\"optional\" style=\"display:none\"><br>\n\n            <label for=\"roof_material\" class=\"optional\" style=\"display:none\">Roof Material:<\/label>\n            <input type=\"text\" id=\"roof_material\" name=\"roof_material\" class=\"optional\" style=\"display:none\"><br>\n\n            <label for=\"roof_service\" class=\"optional\" style=\"display:none\">Roof Service:<\/label>\n            <input type=\"text\" id=\"roof_service\" name=\"roof_service\" class=\"optional\" style=\"display:none\"><br>\n\n            <label for=\"windows_service\" class=\"optional\" style=\"display:none\">Windows Service:<\/label>\n            <input type=\"text\" id=\"windows_service\" name=\"windows_service\" class=\"optional\" style=\"display:none\"><br>\n\n            <label for=\"windows_number\" class=\"optional\" style=\"display:none\">Windows Number:<\/label>\n            <input type=\"text\" id=\"windows_number\" name=\"windows_number\" class=\"optional\" style=\"display:none\"><br>\n\n            <label for=\"bathroom_service\" class=\"optional\" style=\"display:none\">Bathroom Service:<\/label>\n            <input type=\"text\" id=\"bathroom_service\" name=\"bathroom_service\" class=\"optional\" style=\"display:none\"><br>\n\n            <label for=\"hvac_service\" class=\"optional\" style=\"display:none\">HVAC Service:<\/label>\n            <input type=\"text\" id=\"hvac_service\" name=\"hvac_service\" class=\"optional\" style=\"display:none\"><br>\n\n            <label for=\"hvac_system_type\" class=\"optional\" style=\"display:none\">HVAC System Type:<\/label>\n            <input type=\"text\" id=\"hvac_system_type\" name=\"hvac_system_type\" class=\"optional\" style=\"display:none\"><br>\n        <\/div>\n\n        <label for=\"call_recording\">Call Recording:<\/label>\n        <input type=\"text\" id=\"call_recording\" name=\"call_recording\"><br>\n\n        <button type=\"button\" onclick=\"submitForm()\">Submit<\/button>\n    <\/form>\n\n    <script>\n        function isValidUSPhoneNumber(phone) {\n            const phoneRegex = \/^\\(?([0-9]{3})\\)?[-.\\s]?([0-9]{3})[-.\\s]?([0-9]{4})$\/;\n            return phoneRegex.test(phone);\n        }\n\n        function updateFormFields() {\n            const campaignId = document.getElementById('campaign_id').value;\n            const additionalFields = document.querySelectorAll('.optional');\n            additionalFields.forEach(field => field.style.display = 'none');\n\n            if (campaignId === \"3589\") {\n                document.getElementById('bathroom_service').style.display = 'block';\n            } else if (campaignId === \"3590\") {\n                document.getElementById('hvac_service').style.display = 'block';\n                document.getElementById('hvac_system_type').style.display = 'block';\n            } else if (campaignId === \"3591\") {\n                document.getElementById('roof_material').style.display = 'block';\n                document.getElementById('roof_service').style.display = 'block';\n            } else if (campaignId === \"3592\") {\n                document.getElementById('roof_shade').style.display = 'block';\n                document.getElementById('utility_provider').style.display = 'block';\n                document.getElementById('utility_bill_amount').style.display = 'block';\n            } else if (campaignId === \"3593\") {\n                document.getElementById('windows_service').style.display = 'block';\n                document.getElementById('windows_number').style.display = 'block';\n            }\n        }\n\n        function submitForm() {\n            const form = document.getElementById('leadForm');\n            const formData = new FormData(form);\n            const jsonData = {};\n\n            formData.forEach((value, key) => {\n                jsonData[key] = value;\n            });\n\n            \/\/ Validate phone number before submitting\n            const phoneNumber = jsonData['phone_home'];\n            if (phoneNumber && !isValidUSPhoneNumber(phoneNumber)) {\n                alert('Please enter a valid US phone number.');\n                return;\n            }\n\n            fetch('https:\/\/prod-61.westus.logic.azure.com:443\/workflows\/24120cced54f422a94d5fc68cdadf227\/triggers\/manual\/paths\/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=OXZPmXDMi7Dd-Xwr-CPaJ0X8dLMh5WJz18u6usJNGrs', {\n                method: 'POST',\n                headers: {\n                    'Content-Type': 'application\/json'\n                },\n                body: JSON.stringify(jsonData)\n            })\n            .then(response => {\n                console.log('Response:', response);\n                return response.text(); \/\/ Parse response as text for better debugging\n            })\n            .then(data => {\n                try {\n                    const jsonResponse = JSON.parse(data);\n                    console.log('Parsed JSON Response:', jsonResponse);\n                    if (jsonResponse.error) {\n                        alert('Error from server: ' + jsonResponse.error);\n                    } else {\n                        alert('Form submitted successfully!');\n                    }\n                } catch (e) {\n                    console.error('Failed to parse JSON:', e);\n                    console.log('Response Text:', data);\n                    alert('Form submitted, but response could not be parsed as JSON. Response Text: ' + data);\n                }\n            })\n            .catch((error) => {\n                console.error('Error:', error);\n                alert('There was an error submitting the form. Please try again.');\n            });\n        }\n    <\/script>\n<\/body>\n<\/html>\n\n","protected":false},"excerpt":{"rendered":"<p>Lead Form Campaign ID: Select Campaign ID35893590359135923593 First Name: Last Name: Phone Home: Email Address: Address: City: State: Zip Code: Utility Provider: Roof Shade: Utility Bill Amount: Roof Material: Roof Service: Windows Service: Windows Number: Bathroom Service: HVAC Service: HVAC System Type: Call Recording: Submit<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-3626","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/admytelecom.com\/index.php\/wp-json\/wp\/v2\/pages\/3626","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/admytelecom.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/admytelecom.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/admytelecom.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/admytelecom.com\/index.php\/wp-json\/wp\/v2\/comments?post=3626"}],"version-history":[{"count":32,"href":"https:\/\/admytelecom.com\/index.php\/wp-json\/wp\/v2\/pages\/3626\/revisions"}],"predecessor-version":[{"id":3688,"href":"https:\/\/admytelecom.com\/index.php\/wp-json\/wp\/v2\/pages\/3626\/revisions\/3688"}],"wp:attachment":[{"href":"https:\/\/admytelecom.com\/index.php\/wp-json\/wp\/v2\/media?parent=3626"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}