Commit f4a8b0ff by Pham Huy

update form dki tu van

parent 4df88647
......@@ -26,52 +26,101 @@ function form_response($type, $message){
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
$not_human = "Human verification incorrect.";
$missing_content = "Please supply all information.";
$email_invalid = "Email Address Invalid.";
$message_unsent = "Message was not sent. Try Again.";
$message_sent = "Thanks! Your message has been sent.";
$missing_content = "Xin vui lòng điền đầy đủ thông tin cần thiết.";
$taxcode_invalid = "Mã số thuế không hợp lệ.";
$email_invalid = "Email không hợp lệ.";
$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
$taxcode = $_POST['customer_taxcode'];
$company = $_POST['customer_company'];
$address = $_POST['customer_address'];
$city = $_POST['customer_city'];
$email = $_POST['message_email'];
$name = $_POST['customer_name'];
$phone = $_POST['customer_phone'];
$message = $_POST['message_text'];
$human = $_POST['message_human'];
$taxcode = $_POST['customer_taxcode'];
$company = $_POST['customer_company'];
$address = $_POST['customer_address'];
$city = $_POST['customer_city'];
$email = $_POST['customer_email'];
$name = $_POST['customer_name'];
$phone = $_POST['customer_phone'];
$message = $_POST['customer_message'];
$submitted = $_POST['submitted'];
//php mailer variables
$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";
if(!$human == 0){
if($human != 2) form_response("error", $not_human); //not human!
else {
//validate email
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
form_response("error", $email_invalid);
else //email is valid
{
//validate presence of name and message
if(empty($name) || empty($message)){
form_response("error", $missing_content);
}
else //ready to go!
{
$sent = wp_mail($to, $subject, strip_tags($message), $headers);
if($sent) form_response("success", $message_sent); //message sent!
else form_response("error", $message_unsent); //message wasn't sent
}
// var_dump($email);
$check_form = true;
if (!validate_taxcode($taxcode) && !empty($taxcode)) {
//taxcode is valid
form_response("error", $taxcode_invalid);
$check_form = false;
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL) && !empty($email)) {
//email is valid
form_response("error", $email_invalid);
$check_form = false;
}
if(preg_match("/^[0-9]{12}$/", $phone) && !empty($phone)) {
// $phone is valid
form_response("error", $email_invalid);
$check_form = false;
}
//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();
......@@ -107,7 +156,7 @@ get_header();
</style>
<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">
<?php echo $response; ?>
......@@ -118,12 +167,12 @@ get_header();
<!-- mã số thuế -->
<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>
<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>
<!-- Tên công ty -->
<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>
<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>
<!-- Địa chỉ -->
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 form-group">
......@@ -144,12 +193,12 @@ get_header();
<!-- Người liên hệ -->
<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>
<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>
<!-- Số điện thoại -->
<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>
<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>
<!-- Email -->
<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