Created
June 15, 2016 12:29
-
-
Save accessomnath/be9e3e888e9015f39bf6a1fa4bc129d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* template name: real-estate-questionnaire */ | |
get_header(); | |
if(isset($_GET['resp']) && $_GET['resp'] == 'success'){?> | |
<div class="alert alert-info" role="alert"> | |
<span class="glyphicon glyphicon-exclamation-ok" aria-hidden="true"></span> | |
<span class="sr-only">Success:</span> | |
Thank you for contacting Us! | |
</div> | |
<?php | |
} | |
?> | |
<div class="container"> | |
<div class="row well"> | |
<div class="col-md-12"> | |
<form name="myForm" enctype="multipart/form-data" action="" method="post"> | |
<div class="form-group"> | |
First Name:<span class="requerd">*</span> | |
<input class="form-control" name="myFirstName" ng-model="myFirstName" required> | |
<span ng-show="myForm.myFirstName.$touched && myForm.myFirstName.$invalid">First name is required.</span> | |
</div> | |
<div class="form-group"> | |
Last Name:<span class="requerd">*</span> | |
<input class="form-control" name="myLastName" ng-model="myLastName" required> | |
<span ng-show="myForm.myLastName.$touched && myForm.myLastName.$invalid">Last name is required.</span> | |
</div> | |
<div class="form-group"> | |
Email Address:<span class="requerd">*</span> | |
<input class="form-control" name="myEmail" ng-model="myEmail" required type="email" style=" width: 100%;"> | |
<span ng-show="myForm.myEmail.$touched && myForm.myEmail.$invalid">Email is required.</span> | |
</div> | |
<div class="form-group"> | |
Phone Number:<span class="requerd">*</span> | |
<input type="number" class="form-control" name="myPhone" ng-model="myPhone" required > | |
<span ng-show="myForm.myPhone.$touched && myForm.myPhone.$invalid">Phone is required.</span> | |
</div> | |
<div class="form-group"> | |
Address Line 1:<span class="requerd">*</span> | |
<input class="form-control" name="myAddressOne" ng-model="myAddressOne" required> | |
<span ng-show="myForm.myAddressOne.$touched && myForm.myAddressOne.$invalid">First Address is required.</span> | |
</div> | |
<div class="form-group"> | |
Address Line 2:<span class="requerd">*</span> | |
<input class="form-control" name="myAddressTwo" ng-model="myAddressTwo" required> | |
<span ng-show="myForm.myAddressTwo.$touched && myForm.myAddressTwo.$invalid">Second Address is required.</span> | |
</div> | |
<label class="control-label" for="realEstateInterest">Real Estate interest</label> | |
<div class="checkbox"> | |
<label class="checkbox-inline"> | |
<input type="checkbox" name="realEstateInterest[]" id="realEstateInterest" value="residential"> | |
Residential | |
</label> | |
<label class="checkbox-inline"> | |
<input type="checkbox" name="realEstateInterest[]" value="Mix Use"> | |
Mix Use | |
</label> | |
<label class="checkbox-inline"> | |
<input type="checkbox" name="realEstateInterest[]" value="Multi Family"> | |
Multi-Family | |
</label> | |
<label class="checkbox-inline"> | |
<input type="checkbox" name="realEstateInterest[]" value="Commercial"> | |
Commercial | |
</label> | |
<label class="checkbox-inline"> | |
<input type="checkbox" name="realEstateInterest[]" value="Hotel"> | |
Hotel | |
</label> | |
<label class="checkbox-inline"> | |
<input type="checkbox" name="realEstateInterest[]" value="Land"> | |
Land | |
</label> | |
<label class="checkbox-inline"> | |
<input type="checkbox" name="realEstateInterest[]" value="Other"> | |
Other | |
</label> | |
</div> | |
<label class="control-label" for="purchase_requirements">Purchase Requirements</label> | |
<div class="checkbox"> | |
<label class="checkbox-inline"> | |
<input type="checkbox" name="purchase_requirements[]" value="Cash Buyers"> | |
Cash Buyers | |
</label> | |
<label class="checkbox-inline"> | |
<input type="checkbox" name="purchase_requirements[]" value="Hard Money"> | |
Hard Money | |
</label> | |
<label class="checkbox-inline"> | |
<input type="checkbox" name="purchase_requirements[]" value="Commercial Financing"> | |
Commercial Financing | |
</label> | |
<label class="checkbox-inline"> | |
<input type="checkbox" name="purchase_requirements[]" value="Residential Financing"> | |
Residential Financing | |
</label> | |
<label class="checkbox-inline"> | |
<input type="checkbox" name="purchase_requirements[]" value="Real Estate Trust"> | |
Real Estate Trust | |
</label> | |
<label class="checkbox-inline"> | |
<input type="checkbox" name="purchase_requirements[]" value="Business Financing"> | |
Business Financing | |
</label> | |
<label class="checkbox-inline"> | |
<input type="checkbox" name="purchase_requirements[]" value="Other Financing"> | |
Other Financing | |
</label> | |
</div> | |
<label class="control-label" for="proofFunds">Proof of Funds</label> | |
<div class="radio"> | |
<label> | |
<input type="radio" ng-model="proofFunds" name="proofFunds" id="proofFunds" value="1" > | |
Yes | |
</label> | |
</div> | |
<div class="radio"> | |
<label> | |
<input type="radio" ng-model="proofFunds" name="proofFunds" id="proofFunds" value="0" checked> | |
No | |
</label> | |
<div class="form-group" ng-show="proofFunds == '1'"> | |
Attach: | |
<input type="file" id="proof" name="proof"> | |
</div> | |
</div> | |
<label class="control-label" for="realEstateAgent">Real Estate Agent</label> | |
<div class="radio"> | |
<label> | |
<input type="radio" name="realEstateAgent" ng-model="realEstateAgent" id="realEstateAgent" value="1" > | |
Yes | |
</label> | |
</div> | |
<div class="radio"> | |
<label> | |
<input type="radio" name="realEstateAgent" ng-model="realEstateAgent" id="realEstateAgent" value="0"> | |
No | |
</label> | |
<div class="form-group" ng-show="realEstateAgent == '1'"> | |
Commission Rate: | |
<input class="form-control" name="commission_rate" ng-model="commission_rate" > | |
</div> | |
<div class="form-group" ng-show="realEstateAgent == '0'"> | |
Do you need one: | |
<input class="form-control" name="doYouNeedOne" ng-model="doYouNeedOne" > | |
</div> | |
</div> | |
<label class="control-label" for="inputSuccess1">Closing (pick all applicable)</label> | |
<div class="checkbox"> | |
<label class="checkbox-inline"> | |
<input type="checkbox" name="closing[]" value="lawyer"> | |
Lawyer | |
</label> | |
<label class="checkbox-inline"> | |
<input type="checkbox" name="closing[]" value="title company"> | |
Title Company | |
</label> | |
<label class="checkbox-inline"> | |
<input type="checkbox" name="closing[]" value="person HUD-1"> | |
Person HUD-1 | |
</label> | |
<label class="checkbox-inline"> | |
<input type="checkbox" name="closing[]" value="other"> | |
Other | |
</label> | |
</div> | |
<input type="submit" name="submit" ng-click="submitted=true" class="btn btn-primary btn-large" value="submit"> | |
</form> | |
</div> | |
</div> | |
</div> | |
</div> | |
<?php | |
if (isset($_POST['submit'])) { | |
// EDIT THE 2 LINES BELOW AS REQUIRED | |
$email_to = "[email protected], [email protected]"; | |
$email_subject = "Real estate enquery"; | |
function died($error) | |
{ | |
// your error code can go here | |
echo "We are very sorry, but there were error(s) found with the form you submitted. "; | |
echo "These errors appear below.<br /><br />"; | |
echo $error . "<br /><br />"; | |
echo "Please go back and fix these errors.<br /><br />"; | |
die(); | |
} | |
// validation expected data exists | |
if (!isset($_POST['myFirstName']) || | |
!isset($_POST['myLastName']) || | |
!isset($_POST['myEmail']) || | |
!isset($_POST['myPhone']) || | |
!isset($_POST['myAddressOne'])|| | |
!isset($_POST['myAddressTwo'])) | |
{ | |
died('We are sorry, but there appears to be a problem with the form you submitted.'); | |
} | |
$first_name = $_POST['myFirstName']; // required | |
$last_name = $_POST['myLastName']; // required | |
$email = $_POST['myEmail']; // required | |
$phone = $_POST['myPhone']; // required | |
$addressOne = $_POST['myAddressOne']; // required | |
$addressTwo = $_POST['myAddressTwo']; // required | |
$realEstateInterest = $_POST['realEstateInterest']; | |
if (isset($realEstateInterest) && count($realEstateInterest) > 0) { | |
$realEstateInterest = implode(',', $realEstateInterest); | |
} else { | |
$realEstateInterest = ''; | |
} | |
$purchaseReqirement = $_POST['purchase_requirements']; | |
if (isset($purchaseReqirement) && count($purchaseReqirement) > 0) { | |
$purchaseReqirement = implode(',', $purchaseReqirement); | |
} else { | |
$purchaseReqirement = ''; | |
} | |
$proofOfFunds = $_POST['proofFunds']; | |
$proof= $_POST['proof']; | |
if (isset($proofOfFunds) && $proofOfFunds == 1) { | |
move_uploaded_file($_FILES["proof"]["tmp_name"],WP_CONTENT_DIR .'/uploads/'.basename($_FILES['proof']['name'])); | |
$attachments = array(WP_CONTENT_DIR ."/uploads/".$_FILES["proof"]["name"]); | |
} else { | |
$proofOfFunds = "No"; | |
} | |
$realEstateAgent = $_POST['realEstateAgent']; | |
$commission_rate = $_POST['commission_rate']; | |
$doYouNeedOne = $_POST['doYouNeedOne']; | |
if (isset($realEstateAgent) && $realEstateAgent == 1) { | |
$realEstateAgent = $commission_rate; | |
} else { | |
$realEstateAgent = $doYouNeedOne; | |
} | |
$closingPickAll = $_POST['closing']; | |
if (isset($closingPickAll) && count($closingPickAll) > 0) { | |
$closingPickAll = implode(',', $closingPickAll); | |
} else { | |
$closingPickAll = ''; | |
} | |
$error_message = ""; | |
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; | |
if (!preg_match($email_exp, $email)) { | |
$error_message .= 'The Email Address you entered does not appear to be valid.<br />'; | |
} | |
$string_exp = "/^[A-Za-z .'-]+$/"; | |
if (!preg_match($string_exp, $first_name )) { | |
$error_message .= 'The First Name you entered does not appear to be valid.<br />'; | |
} | |
if (strlen($error_message) > 0) { | |
died($error_message); | |
} | |
$email_message = "Form details below.\n\n"; | |
function clean_string($string) | |
{ | |
$bad = array("content-type", "bcc:", "to:", "cc:", "href"); | |
return str_replace($bad, "", $string); | |
} | |
$email_message = "Hello Admin, You have got a new contact with following details: \n\n"; | |
$email_message .= "First Name : " . clean_string($first_name) . "\n"; | |
$email_message .= "Last Name : " . clean_string($last_name) . "\n"; | |
$email_message .= "Email : " . clean_string($email) . "\n"; | |
$email_message .= "Phone : " . clean_string($phone) . "\n"; | |
$email_message .= "Address one : " . clean_string($addressOne) . "\n"; | |
$email_message .= "Address two : " . clean_string($addressTwo) . "\n"; | |
$email_message .= "Real estate interest : " . clean_string($realEstateInterest) . "\n"; | |
$email_message .= "Purchase requirement : " . clean_string($purchaseReqirement) . "\n"; | |
$email_message .= "Real estate agent : " . clean_string($realEstateAgent) . "\n"; | |
$email_message .= "Close pick all : " . clean_string($closingPickAll) . "\n\n\n"; | |
$email_message .="Thanks & Regards, \n" . $first_name ." ". $last_name ; | |
$headers = "From: ". $email . "\r\n"; | |
$headers .= "Reply-To: " . $email . "\r\n"; | |
$headers .= "X-Mailer: PHP/" . phpversion() ; | |
$headers .= "MIME-Version: 1.0" . "\r\n"; | |
$mail = wp_mail($email_to, $email_subject , $email_message , $headers, $attachments); | |
echo $mail ? "Thank you for connecting with us! We will contact you shortly!" : " Mail failed"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment