Codeigniter Tutorials
- What is codeigniter?
- Application_Architecture
- MVC Architecture
- HMVC Architecture
- Codeigniter Configuration
- Remove index.php from url in codeigniter
- MVC Concept
- View
- Alternate PHP Syntax for View Files
- Routing
- Codeigniter URL
- Get Current URL
- Previous page URL get
- Seo Friendly URL
- Slug Create in codeigniter
- What is _remap() function
- Remove controller name from url in codeigniter
- Codeigniter Controller Class
- Class Constructor
- GET $ POST method in Codeigniter
- Models
- Basepath, Apppath, FCPATH
- URI Segment
- Page Redirect
- Helper class
- Custom Helper class
- Form Helper
- Common Helper Functions
- Common Function
- Array Problems
- Call controller in Helper
- Add active class to menu using Helper class
- Custom Library
- Custom Library Example
- when to use get_instance()
- Codeigniter Hook
- how to work inline css in codeigniter
- Custom 404 page
- 404 custom error page
- Create custom config file in codeigniter
- How to set and get config item value
- How to Speed Up CodeIgniter App?
- Codeigniter Functions
- Session
- cookies
- How to Set & Get Tempdata in Codeigniter
- flash messages in Codeigniter
- Flashdata
- Encryption and Decryption In CodeIgniter
- Codeigniter security
- csrf token form security
- Password Hashing
- Form Validation
- Custom Validation
- Registration Form with validation
- Server Side Form Validation
- Validate Select Option Field
- Date Format Validation
- Date Format change in codeigniter
- Date Functions
- DOB Validation
- CI CRUD
- User SignUp
- User Login
- User Logout
- Login Account
- Login form with RememberMe
- Login Form with session
- User change password
- Change Password with Callback Validation to Check Old Password
- Forgot password
- Reset password
- Insert data in database
- Fetch data from database
- Update data in database
- Delete data in database
- File Upload
- Image Upload with resize Image
- Upload Multiple file and images
- Upload Multiple images with CRUD
- File and image update
- Upload Image Using Ajax.
- Email Send
- Email Send Using Email library
- Email Send Using SMTP Gmail
- Notification send
- store data in json format in DB
- Json parse
- Fetch data Using Ajax with Json data
- How to Show data Using Ajax with Json parse
- Get JSON Data from PHP Script using jQuery Ajax
- Insert data Using Ajax
- Submit data Using Ajax with form validation
- How to show data Using Ajax in codeigniter
- Insert & Update Using Ajax
- Registration Form With Validation Using Ajax in codeigniter
- Delete data Using Ajax Confirmation
- Delete All data Using checkbox selection
- Ajax CSRF Token
- Ajax Post
- Ajax serverside form validation
- Contact form using AJAX with form validation
- DataTable Using Ajax dynamically
- DataTables pagination using AJAX with Custom filter
- DataTables AJAX Pagination with Search and Sort in codeigniter
- DataTables in Codeigniter using Ajax
- Ajax Custom Serarch
- Ajax Live Data Search using Jquery PHP MySql
- Ajax Custom Serarch and sorting in datatable
- Dynamic Search Using Ajax
- Autocomplete using jquery ajax
- Jquery Ajax Autocomplete Search using Typeahead
- Dynamic Dependent Dropdown Using Ajax
- Dynamic Dependent Dropdown list Using Ajax
- Dynamic Dependent Dropdown in codeigniter using Ajax
- ajax username/email availability check using JQuery
- Check Email Availability Using Ajax
- Data Load on mouse scroll
- Ajax CI Pagination
- Pagination in codeigniter
- Ajax Codeigniter Pagination
- email exists or not using ajax with json
- CRUD using AJAX With Modal popup in CI
- Add / Show Data on modal popup using Ajax
- Modal popup Validation using Ajax
- Data show on Modal popup Using Ajax
- Add / Remove text field dynamically using jquery ajax
- How to Add/Delete Multiple HTML Rows using JavaScript
- Delete Multiple Rows using Checkbox
- Multiple Checkbox value
- Form submit using jquery Example
- REST & SOAP API
- Multi-Language implementation in CodeIgniter
- How to pass multiple array in view
- Captcha
- create zip file and download
- PhpOffice PhpSpreadsheet Library (Export data in excel sheet)
- data export in excel sheet
- Excel File generate in Codeigniter using PHPExcel
- Dompdf library
- tcpdf library
- Html table to Excel & docs download
- CI Database Query
- Database Query
- SQL Injection Prevention
- Auth Model
- Join Mysql
- Tree View in dropdown option list
- OTP Integration in codeigniter
- curl post
- download file using curl
- Sweet Alert
- Sweet alert Delete & Success
- Log Message in Codeigniter
- Menu & Submenu show dynamically
- Set Default value in input box
- Cron Jobs
- Stored Procedure
- Display Loading Image when AJAX call is in Progress
- Send SMS
- IP Address
- Codeigniter Tutorialspoint
- Website Link
- How To Create Dynamic Xml Sitemap In Codeigniter
- Paypal Payment Integration
- Get Latitude and Longitude From Address in Codeigniter Using google map API
- How To Create Simple Bar Chart In Codeigniter Using AmCharts?
- dynamic Highcharts in Codeigniter
- Barcode in Codeigniter
- Codeigniter Interview Questions
- Project
Home » Codeigniter »
How to validate email and mobile number in database using ajax with json data.
User registration before check email or mobile no exists or not in database.
File name : signup.php
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title> </title>
<!-- Fonts -->
<link rel="dns-prefetch" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css?family=Raleway:300,400,600" rel="stylesheet" type="text/css">
<link rel="icon" href="Favicon.png">
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<style type="text/css">
@import url(https://fonts.googleapis.com/css?family=Raleway:300,400,600);
body{
margin: 0;
font-size: .9rem;
font-weight: 400;
line-height: 1.6;
color: #212529;
text-align: left;
background-color: #f5f8fa;
}
.navbar-laravel
{
box-shadow: 0 2px 4px rgba(0,0,0,.04);
}
.navbar-brand , .nav-link, .my-form, .login-form
{
font-family: Raleway, sans-serif;
}
.my-form
{
padding-top: 1.5rem;
padding-bottom: 1.5rem;
}
.my-form .row
{
margin-left: 0;
margin-right: 0;
}
.login-form
{
padding-top: 1.5rem;
padding-bottom: 1.5rem;
}
.login-form .row
{
margin-left: 0;
margin-right: 0;
}
</style>
<script type="text/javascript">
function validform() {
var a = document.forms["my-form"]["name"].value;
var b = document.forms["my-form"]["email"].value;
var c = document.forms["my-form"]["user_id"].value;
var d = document.forms["my-form"]["mobile_number"].value;
if (a==null || a=="")
{
alert("Please Enter Your Full Name");
return false;
}else if (b==null || b=="")
{
alert("Please Enter Your Email Address");
return false;
}else if (c==null || c=="")
{
alert("Please Enter Your Username");
return false;
}else if (d==null || d=="")
{
alert("Please Enter Your MobileNo");
return false;
}
}
</script>
<script type="text/javascript">
function check_if_exists_email() {
var email = $("#email").val();
$.ajax(
{
type:"post",
url: "<?php echo base_url(); ?>login/user_email_exists",
data:{ useremail:email},
dataType: 'json',
success:function(response)
{
var len = response.length;
if(len > 0)
{
$('#msg').html('<span style="color: red;">This Email already exists</span>');
$("input[type=submit]").attr("disabled", "disabled");
}
else
{
$('#msg').html('<span style="color:green;">OK</span>');
$("input[type=submit]").removeAttr("disabled");
}
}
});
}
</script>
<script type="text/javascript">
function check_if_exists_mobile()
{
var mobile = $("#mobile_number").val();
$.ajax(
{
type:"post",
url: "<?php echo base_url(); ?>login/user_mobile_exists",
data:{ mobile:mobile},
dataType: 'json',
success:function(response)
{
var len = response.length;
if(len > 0)
{
$('#msg').html('<span style="color: red;">This mobile no already exists</span>');
$("input[type=submit]").attr("disabled", "disabled");
}
else
{
$('#msg').html('<span style="color:green;">OK</span>');
$("input[type=submit]").removeAttr("disabled");
}
}
});
}
</script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light navbar-laravel">
<div class="container">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="#">Login</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Register</a>
</li>
</ul>
</div>
</div>
</nav>
<main class="my-form">
<div class="cotainer">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header"><center><div id="msg"></div></center></div>
<div class="card-body">
<form name="my-form" onsubmit="return validform()" action="<?php echo base_url()?>login/signupuser" method="post">
<div class="form-group row">
<label for="full_name" class="col-md-4 col-form-label text-md-right">Full Name</label>
<div class="col-md-6">
<input type="text" id="name" class="form-control" name="name">
</div>
</div>
<div class="form-group row">
<label for="email_address" class="col-md-4 col-form-label text-md-right">E-Mail Address</label>
<div class="col-md-6">
<input type="text" id="email" class="form-control" name="email" onblur="check_if_exists_email();">
</div>
</div>
<div class="form-group row">
<label for="user_name" class="col-md-4 col-form-label text-md-right">User Id</label>
<div class="col-md-6">
<input type="text" id="user_id" class="form-control" name="user_id">
</div>
</div>
<div class="form-group row">
<label for="phone_number" class="col-md-4 col-form-label text-md-right">Phone Number</label>
<div class="col-md-6">
<input type="text" id="mobile_number" name="mobile_number" class="form-control" onblur="check_if_exists_mobile();">
</div>
</div>
<div class="col-md-6 offset-md-4">
<input type="submit" class="btn btn-primary" value="Submit"/>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</main>
</body>
</html>
Controller :
File name : index.php
<?php
defined('BASEPATH') OR exit('no direct script access allowed');
class Login extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('login');
}
public function signup()
{
$this->load->view('signup');
}
public function user_email_exists()
{
$uemail = $this->input->post('useremail');
$data = $this->Auth_model->check_email_exists($uemail);
echo json_encode($data);
exit;
}
public function user_mobile_exists()
{
$mobileno = $this->input->post('mobile');
$data = $this->Auth_model->check_mobile_exists($mobileno);
echo json_encode($data);
exit;
}
public function signupuser()
{
/*$que=$this->db->query("select * from user_info where user_email='".$em."' and user_mobileno='".$mob."'");
$row = $que->num_rows();
if($row){ }else{ }
*/
$email=$this->input->post('email');
$mobile=$this->input->post('mobile_number');
$validmember = $this->Auth_model->validatedata($email,$mobile);
if($validmember == true)
{
echo "sorry data already available in database";
}
else{
$data = array(
'name' => $this->input->post('name'),
'email' => $this->input->post('email'),
'user_id' => $this->input->post('user_id'),
'mobileno' => $this->input->post('mobile_number')
);
$result = $this->Auth_model->signup_user($data);
return $result;
}
}
}
model :
File name : Auth_model.php
<?php
defined('BASEPATH') OR exit ('no direct script access allowed');
class Auth_model extends CI_Model
{
public function __construct()
{
parent::__construct();
}
public function user_present($email)
{
$this->db->select('*');
$this->db->from('user_info');
$this->db->where('email', $email);
$qry = $this->db->get();
return $qry->result();
}
public function check_email_exists($uemail)
{
/* $qry = "select * from user_info where email = '$uemail'";
$result = $this->db->query($qry);
return $result->num_rows();
*/
$this->db->select('email');
$this->db->from('user_info');
$this->db->where('email', $uemail);
$qry = $this->db->get();
return $qry->result();
}
public function check_mobile_exists($mobileno)
{
$this->db->select('mobileno');
$this->db->from('user_info');
$this->db->where('mobileno', $mobileno);
$qry = $this->db->get();
return $qry->result();
}
public function get_user($username, $email)
{
$qry = "select * from user_info where user_id='$username' and email = '$email'";
$result = $this->db->query($qry);
return $result->num_rows();
}
public function validatedata($email,$mobile)
{
// use multiple where clause
$wherearray = array(
'email' => $email,
'mobileno' => $mobile
);
$this->db->select('email','mobileno');
$this->db->from('user_info');
//$this->db->where('email', $email);
//$this->db->where('mobileno', $mobile);
$this->db->where($wherearray);
$qry = $this->db->get();
return $qry->result();
/*
$que=$this->db->query("select * from user_info where email='".$email."' and mobileno='".$mobile."'");
$row = $que->num_rows();
return $row;
*/
}
public function signup_user($data)
{
$this->db->insert('user_info', $data);
return;
}
}
File name : index.php