Commit f4a8b0ff by Pham Huy

update form dki tu van

parent 4df88647
...@@ -26,52 +26,101 @@ function form_response($type, $message){ ...@@ -26,52 +26,101 @@ function form_response($type, $message){
else $response = "<div class='error'>{$message}</div>"; else $response = "<div class='error'>{$message}</div>";
} }
// verify recaptcha V3
function checkRecaptcha()
{
$key_sr = '6LdX5tYUAAAAAB68LkKNZC5bsfaAN8xbkph2v1yR';
$url = 'https://www.google.com/recaptcha/api/siteverify';
$response = wp_remote_post( $url, array(
'method' => 'POST',
// 'redirection' => 5,
// 'httpversion' => '1.0',
// 'blocking' => true,
// 'headers' => array(),
'body' => array(
'secret' => $key_sr,
)
)
);
if ( is_wp_error( $response ) ) {
$error_message = $response->get_error_message();
echo "Something went wrong: $error_message";
} else {
echo 'Response:<pre>';
print_r( $response );
echo '</pre>';
}
}
//response messages //response messages
$not_human = "Human verification incorrect."; $not_human = "Human verification incorrect.";
$missing_content = "Please supply all information."; $missing_content = "Xin vui lòng điền đầy đủ thông tin cần thiết.";
$email_invalid = "Email Address Invalid."; $taxcode_invalid = "Mã số thuế không hợp lệ.";
$message_unsent = "Message was not sent. Try Again."; $email_invalid = "Email không hợp lệ.";
$message_sent = "Thanks! Your message has been sent."; $phone_invalid = "Số điện thoại không hợp lệ.";
$message_unsent = "Đã xảy ra lỗi, vui lòng kiểm tra lại.";
$message_sent = "Cảm ơn khách hàng đã đăng ký! Chúng tôi sẽ liên hệ lại sớm nhất.";
//user posted variables //user posted variables
$taxcode = $_POST['customer_taxcode']; $taxcode = $_POST['customer_taxcode'];
$company = $_POST['customer_company']; $company = $_POST['customer_company'];
$address = $_POST['customer_address']; $address = $_POST['customer_address'];
$city = $_POST['customer_city']; $city = $_POST['customer_city'];
$email = $_POST['message_email']; $email = $_POST['customer_email'];
$name = $_POST['customer_name']; $name = $_POST['customer_name'];
$phone = $_POST['customer_phone']; $phone = $_POST['customer_phone'];
$message = $_POST['message_text']; $message = $_POST['customer_message'];
$human = $_POST['message_human']; $submitted = $_POST['submitted'];
//php mailer variables //php mailer variables
$to = get_option('admin_email'); $to = get_option('admin_email');
$subject = "Someone sent a message from ".get_bloginfo('name'); $subject = "Khách hàng đăng ký tư vấn ".get_bloginfo('name');
$headers = 'From: '. $email . "\r\n" . 'Reply-To: ' . $email . "\r\n"; $headers = 'From: '. $email . "\r\n" . 'Reply-To: ' . $email . "\r\n";
if(!$human == 0){ // var_dump($email);
if($human != 2) form_response("error", $not_human); //not human! $check_form = true;
else { if (!validate_taxcode($taxcode) && !empty($taxcode)) {
//taxcode is valid
//validate email form_response("error", $taxcode_invalid);
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) $check_form = false;
form_response("error", $email_invalid); }
else //email is valid if (!filter_var($email, FILTER_VALIDATE_EMAIL) && !empty($email)) {
{ //email is valid
//validate presence of name and message form_response("error", $email_invalid);
if(empty($name) || empty($message)){ $check_form = false;
form_response("error", $missing_content); }
} if(preg_match("/^[0-9]{12}$/", $phone) && !empty($phone)) {
else //ready to go! // $phone is valid
{ form_response("error", $email_invalid);
$sent = wp_mail($to, $subject, strip_tags($message), $headers); $check_form = false;
if($sent) form_response("success", $message_sent); //message sent! }
else form_response("error", $message_unsent); //message wasn't sent
} //validate form to sent mail
if($check_form && $submitted == 1){
//validate presence of name and message
if(empty($taxcode) || empty($company) || empty($name) || empty($phone)){
form_response("error", $missing_content);
} else {
//ready to go!
$content_mail = "Gửi đến từ: Ahoadon.com<br>
Khách hàng: ".$name." đã đăng ký tư vấn trở thành đại lý Ahoadon<br>
Công ty : ".$company."<br>
Mã số thuế : ".$taxcode."<br>
Số điện thoại : ".$phone."<br>
Địa chỉ : ".$address."<br>
Tỉnh/ Thành phố: ".$city."<br>
Nội dung : ".$message."
-----------------
Email này được gửi đến từ form Đăng ký tư vấn đại lý của website ahoadon.com";
$sent = wp_mail($to, $subject, $content_mail, $headers);
if($sent) form_response("success", $message_sent); //message sent!
else form_response("error", $message_unsent); //message wasn't sent
} }
}
} }
else if ($_POST['submitted']) form_response("error", $missing_content);
get_header(); get_header();
...@@ -107,7 +156,7 @@ get_header(); ...@@ -107,7 +156,7 @@ get_header();
</style> </style>
<section class="container" id="register-customer"> <section class="container" id="register-customer">
<h2 class="register-title">Đăng ký sử dụng</h2> <h2 class="register-title">Đăng ký tư vấn sử dụng</h2>
<div id="form-register-customer"> <div id="form-register-customer">
<?php echo $response; ?> <?php echo $response; ?>
...@@ -118,12 +167,12 @@ get_header(); ...@@ -118,12 +167,12 @@ get_header();
<!-- mã số thuế --> <!-- mã số thuế -->
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 form-group"> <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 form-group">
<label for="customer_taxcode">Mã số thuế: <span class="txt-red">*</span></label> <label for="customer_taxcode">Mã số thuế: <span class="txt-red">*</span></label>
<input type="text" class="form-control" name="customer_taxcode" id="customer_taxcode" value="<?php echo esc_attr($_POST['customer_taxcode']); ?>"> <input type="text" class="form-control" name="customer_taxcode" id="customer_taxcode" required value="<?php echo esc_attr($_POST['customer_taxcode']); ?>">
</div> </div>
<!-- Tên công ty --> <!-- Tên công ty -->
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 form-group"> <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 form-group">
<label for="customer_company">Tên công ty: <span class="txt-red">*</span></label> <label for="customer_company">Tên công ty: <span class="txt-red">*</span></label>
<input type="text" class="form-control" name="customer_company" id="customer_company" value="<?php echo esc_attr($_POST['customer_company']); ?>"> <input type="text" class="form-control" name="customer_company" id="customer_company" required value="<?php echo esc_attr($_POST['customer_company']); ?>">
</div> </div>
<!-- Địa chỉ --> <!-- Địa chỉ -->
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 form-group"> <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 form-group">
...@@ -144,12 +193,12 @@ get_header(); ...@@ -144,12 +193,12 @@ get_header();
<!-- Người liên hệ --> <!-- Người liên hệ -->
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 form-group"> <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 form-group">
<label for="customer_name">Người liên hệ: <span class="txt-red">*</span> </label> <label for="customer_name">Người liên hệ: <span class="txt-red">*</span> </label>
<input type="text" class="form-control" name="customer_name" id="customer_name" value="<?php echo esc_attr($_POST['customer_name']); ?>"> <input type="text" class="form-control" name="customer_name" id="customer_name" required value="<?php echo esc_attr($_POST['customer_name']); ?>">
</div> </div>
<!-- Số điện thoại --> <!-- Số điện thoại -->
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 form-group"> <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 form-group">
<label for="customer_phone">Số điện thoại: <span class="txt-red">*</span> </label> <label for="customer_phone">Số điện thoại: <span class="txt-red">*</span> </label>
<input type="text" class="form-control" name="customer_phone" id="customer_phone" placeholder="Số điện thoại" value="<?php echo esc_attr($_POST['customer_phone']); ?>"> <input type="text" class="form-control" name="customer_phone" id="customer_phone" required placeholder="Số điện thoại" value="<?php echo esc_attr($_POST['customer_phone']); ?>">
</div> </div>
<!-- Email --> <!-- Email -->
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 form-group"> <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 form-group">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment