[eluser]Noobigniter[/eluser]
Hello,
I can not find the code that I used to check the Nickname, however I always the one for email, so just change the ID in html, and "filter" in javascript.
That's the code:
// IN MY USERS CONTROLLER
Code:
<?php
function email_disponibilite()
{
$this->load->model('user_model');
$get_result = $this->user->email_disponibilite();
if(!$get_result)
echo '<span class="error">Cet email est déja utilisé.</span>';
else
echo '<span class="success">Cet email est disponible.</span>';
}
?>
// IN MY USERS MODEL
Code:
<?php
function email_disponibilite($email = '')
{
$email = strtolower($this->input->post('email', TRUE));
$query = $this->db->query('SELECT id FROM users WHERE email = ?', $email);
return ($query->num_rows() > 0) ? FALSE : TRUE;
}
?>
//
// IN MY USERS VIEW
Code:
<form>
<p>Email:<br />
<?php echo form_input($email);?>
<span id="Loading"><img src="<?=base_url();?>images/site/loader.gif" alt="Ajax Indicator" /></span>
<span id="reponse_dispo_email"></span>
</p>
</form>
// JAVASCRIPT
Code:
<!-- insert jQuery/JS files -->
[removed]
// Disponibilité email
$(document).ready(function() {
$('#Loading').hide();
$('#email').blur(function(){
var a = $("#email").val();
var filtre = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
if(filtre.test(a)){
$('#Loading').show();
$.post( "<?php echo base_url();?>users/email_disponibilite/", { email: $('#email').val() },
function(response){
$('#Loading').hide();
setTimeout(function(){ finishAjax('Loading', escape(response)); },400);
}
);
return false;
}
});
function finishAjax(id, response){
$('#'+id).html(unescape(response));
$('#'+id).fadeIn();
}
});
[removed]
Hope this helps you ...
Cordially.