我想使用json(或ajax?)检查数据库中opencart注册页面中的电子邮件,因此如果可用或不可用,注册表中会有一个注释。
请帮忙吗? 感谢
好的,这就是我到目前为止所做的事情
signup.tpl
<tr>
<td><span class="required">*</span> <?php echo $entry_email; ?><br />
<div id="email_availability_result"></div>
</td>
</tr>
<tr>
<td><input type="text" id="email" class="form-control" name="email" value="<?php echo $email; ?>" />
<?php if ($error_email) { ?>
<span class="error"><?php echo $error_email; ?></span>
<?php } ?></td>
</tr>
signup.tpl
<script type="text/javascript">
$(document).ready(function(){
$('#email').keyup(function(){
var email = $('#email').val();
if(email.length > 2) {
$('#email_availability_result').html('Loading..');
var post_string = 'email='+email;
$.ajax({
dataType: 'json',
type : 'POST',
data : post_string,
url: 'index.php?route=account/signup/emailCheck',
success: function(json) {
$('.success, .warning, .attention, information, .error').remove();
if (json['success']) {
$('#email_availability_result').html('<span class="success">' + json['success'] + '</span>');
}
if (json['warning']) {
$('#email_availability_result').html('<span class="success">' + json['warning'] + '</span>');
}
}
});
}else{
$('#email_availability_result').html('');
}
});
});
signup.php(控制器)
public function emailCheck() {
$this->load->model('account/signup');
$json = array();
if(isset($this->request->post['email'])){
$email = $this->request->post['email'];
$result = $this->model_account_signup->getEmailBySignUp($email);
$json['success'] = "Email name available";
$json['warning'] = "Email already taken";
}
$this->response->setOutput(json_encode($json));
}
signup.php(型号)
public function getEmailBySignUp($email) {
$query = $this->db->query("SELECT count(*) as total FROM `" . DB_PREFIX . "user` WHERE email = '" . $this->db->escape($email) . "'");
return $query->row['total'];
}
它不起作用。
答案 0 :(得分:1)
此功能已在打开的购物车中,但它将在页面重新加载时工作。您可以在
上查看 Catalog/accounts/register.php function name getTotalCustomersByEmail()
您可以通过ajax调用此模型功能,并可以显示电子邮件地址检查的即时消息。