$myvars = array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
);
wp_enqueue_script( 'bundle', plugins_url( '/bundle.js', __FILE__ ), array('jquery'), '1.0', true );
wp_localize_script( 'bundle', 'MyAjax', $myvars );
add_action( 'wp_ajax_send_message', 'do_send_message' );
add_action( 'wp_ajax_nopriv_send_message', 'do_send_message' );
function do_send_message() {
if ( isset($_POST['name']) && isset($_POST['email']) &&isset($_POST['message']) ) {
$name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message'];
$send_to = "antibioticvz@gmail.com";
$subject = "Question from " . $name;
$success = wp_mail($send_to,$subject,$message);
if ($succsess) return true;
if (!$succsess) return false;
die();
}
}
getAJAXCall() {
$.ajax({
url: "<?php echo admin_url('admin-ajax.php'); ?>",
success: console.log('Success')
})
},
handleChange() {
var valid = this.validationState();
if (valid) {
this.setState({
disabled: false
});
} else {
this.setState({
disabled: true
});
}
},
/* Antibiotic 26.01.2016
* function to validate email input
*/
validationState() {
var mail = this.refs.mail.getValue();
var checked = this.refs.MyCheckbox.getChecked();
var condition;
var re = /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
if (!re.test(mail)) {
this.setState({
style: "error"
});
}else {
this.setState({
style: null
});
}
if(re.test(mail) && checked ){
condition = true;
return condition
}else {
condition = false;
return condition
}
},
handleChange(source, event) {
var inputFlag;
var checkFlag;
var checked = event.target.checked;
if(source == "CheckConfirm") {
if (checked) {
checkFlag = true;
}else {
checkFlag = false;
}
}
if(source == "InputMail") {
var style = this.validationState();
if (JSON.stringify(style) !== '{"style":"error"}') {
this.setState(this.validationState());
inputFlag = true;
} else {
this.setState(this.validationState());
inputFlag = false;
}
}
console.log(inputFlag +" and "+ checkFlag);
if(inputFlag && checkFlag){
console.log('оба флага вверх');
this.setState({
disabled: false
});
} else {
this.setState({
disabled: true
});
}
},