22 May 2021

How to redirect after checkout in woo-commerce in Wordpress.

Redirect after checkout in woo-commerce in Wordpress. 


Paste in function.php

/*

Redirect loggedin user to order details page

*/

if(is_user_logged_in())

{

add_action( 'template_redirect', 'woocommerce_redirect_after_checkout' );

}

function woocommerce_redirect_after_checkout() {

global $wp;

if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) {

$redirect_url = home_url().'/my-account/view-order/'.$wp->query_vars['order-received'] ;


wp_redirect($redirect_url );


exit;

}

}


How to create custom guest popup for checkout with wordpress menu in wordpress.

Create custom guest popup for checkout with wordpress menu in wordpress.

Paste in function.php

function override_checkout_email_field( $fields ) {
global $wpdb;
  $popup_id = $_COOKIE['popup_id'];
global $wpdb;
$tablename = $wpdb->prefix . "guest_users";
$result = $wpdb->get_results ("SELECT * FROM $tablename WHERE id=$popup_id");
foreach ( $result as $print )   {

}
$survey_email = $print->email;
$survey_phone = $print->phone;
    global $woocommerce;
    //$survey_email = $woocommerce->session->get('survey_email');
    if(!is_null($survey_email)) {
      $fields['billing']['billing_email']['default'] = $survey_email;
    }
     if(!is_null($survey_phone)) {
      $fields['billing']['billing_phone']['default'] = $survey_phone;
    } 
    return $fields;
}

add_filter( 'woocommerce_checkout_fields' , 'override_checkout_email_field' );


// Show the popup to fetch email and phone number and store in the database




function guest_popup(){
$popup_id = $_COOKIE['popup_id'];
if(isset($_POST['guest_popup_bt'])){
$email = $_POST['email'];
$phone = $_POST['phone'];
date_default_timezone_set('Asia/Kolkata');
$date = date('d-m-Y h:i:s a');
global $wpdb;
$table_name = $wpdb->prefix . "guest_users";
$wpdb->insert($table_name, array('email' => $email, 'phone' => $phone, 'created_at' => $date) ); 
$lastid = $wpdb->insert_id;
if(!empty($lastid)){
//setcookie('popup_id', $lastid, strtotime('+1 day'), COOKIEPATH, COOKIE_DOMAIN);
setcookie('popup_id', $lastid, strtotime("+1 year"), COOKIEPATH, COOKIE_DOMAIN);
if ( ! WC()->cart->get_cart_contents_count() == 0 ) { 
wp_redirect(site_url().'/checkout');
}else{
wp_redirect(site_url().'/shop');
}
}
}
?>
<?php
if(!is_user_logged_in() && is_cart() && empty($popup_id)){
?>
<style>
.popup-container {
    width: 100%;
    height: 100vh;
    background-color: #000000bf;
    position: fixed;
    display: flex;
    justify-content: Center;
    align-items: center;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 9999999;
    left: 0;
}

.popup-box input[type="email"],input[type="number"] {
    width: 100%;
    font-size: 15px;
    padding: 7px 7px;
}
input.guest_popup_bt {
    padding: 5px 16px;
    background: #000;
    border: #000;
    color: white;
    font-weight: 400;
    font-size: 16px;
}
.form-filed-box {
    margin-top: 10px;
}
.popup-box h4 {
    margin: 0;
    font-size: 17px;
    text-align: center;
    font-weight: 400;
    letter-spacing: 1px;
    margin-bottom: 12px;
}
.popup-box {
    padding: 59px 37px;
    background: white;
    border-radius: 9px;
    width: 386px;
position:relative;
}

.popup_close_bt {
    background: #000;
    color: White;
    position: absolute;
    right: -15px;
    top: -15px;
    border-radius: 200%;
    width: 30px;
    height: 30px;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
cursor:pointer;
}
</style>
<script>
jQuery(document).ready(function($){
$('.popup_close_bt').click(function(){
$('.popup-container').css('display','none');
});

if (typeof $.cookie('popup_id') === 'undefined'){

$('.checkout-button').click(function(e){
e.preventDefault;
jQuery('.popup-container').css('display','flex');
return false;
});
}
});
</script>
<div class="popup-container">
<div class="popup-box">
<div class="popup_close_bt">X</div>
<form action="" method="post">
<h4>Please enter the following detail to move forward</h4>
<div class="form-filed-box">
<label>Email</label>
<input type="email" name="email" >
</div>
<div class="form-filed-box">
<label>Phone no.</label>
<input type="text" name="phone" >
</div>
<div class="form-filed-box">
<input type="submit" name="guest_popup_bt" class="guest_popup_bt" value="Submit">
</div>
</form>
</div>
</div>
<?php
}
}
add_action('wp_head','guest_popup');


add_action("admin_menu", "addMenu");

function addMenu() {
    add_menu_page("Guest Info", "Guest Info", "edit_posts",
        "guest-popup", "displayPage", null,10);
}

add_filter("custom_menu_order", "allowMenuStructure");
add_filter("menu_order", "loadMenuStructure");

function displayPage() {
?>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.2.2/css/buttons.dataTables.min.css">



<script src="https://code.jquery.com/jquery-1.12.3.js"></script>
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.2.2/js/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.2.2/js/buttons.flash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
<script src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/pdfmake.min.js"></script>
<script src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/buttons/1.2.2/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.2.2/js/buttons.print.min.js"></script>  



<script>

$(document).ready(function() {
    $('#example').DataTable( {
      /*   dom: 'Bfrtip',
        buttons: [
            'copy', 'excelFlash', 'excel', 'pdf', 'print',{
            text: 'Reload',
            action: function ( e, dt, node, config ) {
                dt.ajax.reload();
            }
        }
        ] */
    } );
} );

</script>


<table id="example" class="display nowrap" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>S.r</th>
                <th>Date</th>
                <th>Email</th>
                <th>Phone</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <th>S.r</th>
                <th>Date</th>
                <th>Email</th>
                <th>Phone</th>
            </tr>
        </tfoot>
        <tbody>
<?php
global $wpdb;
$tablename = $wpdb->prefix . "guest_users";
$result = $wpdb->get_results ("SELECT * FROM $tablename order by Id DESC");
//print_r($result);
$i = 1 ;
foreach ( $result as $print )   {
?>
            <tr>
                <td><?php echo $i; ?></td>
                <td><?php echo $print->created_at; ?></td>
                <td><a href="mailto:<?php echo $print->email; ?>"><?php echo $print->email; ?></a></td>
                <td><a href="tel:<?php echo $print->phone; ?>"><?php echo $print->phone; ?></a></td>

            </tr>
<?php
$i++;
}
?>
        </tbody>
    </table>
<?php
}

12 May 2021

PHP file upload - Dynamically Add Remove input fields using JQuery and PHP.

PHP file upload - Dynamically Add Remove input fields using JQuery and PHP.




Paste in View


<style>
.file {
  visibility: hidden;
  position: absolute;
}

.btn.btn-primary {
  background-color: #007bff;
  border-color: #007bff;
  outline: none;
  color: #fff;
}

.multi-cus-filed{
  position:relative;
}

.remove-cus-filed {
background: #007bff;
border-radius: 200%;
padding: 4px 13px;
border: none;
color: white;
font-size: 19px;
position: absolute;
top: 32px;
right: -40px;
}


.multi-cus-filed{
  position:relative;
}

.remove-cus-filed {
background: #007bff;
border-radius: 200%;
padding: 4px 13px;
border: none;
color: white;
font-size: 19px;
position: absolute;
top: 32px;
right: -40px;
}
</style>
  
  
  
<form role="form" action="" method="POST" enctype="multipart/form-data">
<div class="multi-field-wrapper">
  <div class="multi-fields">
<div class="multi-field multi-cus-filed">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="ReportName">Name</label>
<div>
  <input type="text" class="form-control "  name="title[]" placeholder="Enter Report name" >
</div>
</div>
</div>
<div class="col-sm-6">
  <div class="form-group">
<label for="ReportFile">File</label>
<input type="file" name="report[]" class="file">
<div class="input-group mb-3">
  <div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1"><i class="fas fa-paperclip"></i></span>
  </div>
  <input type="text" class="form-control" disabled placeholder="Upload File" aria-label="Upload File" aria-describedby="basic-addon1">
  <div class="input-group-append">
<label class="browse input-group-text btn btn-primary" id="basic-addon2"><i class="fas fa-search"></i>  Choose</label>
  </div>
</div>
  </div>
</div>
</div>
  <button type="button" class="remove-field remove-cus-filed">X</button>
</div>
  </div>
<button type="button" class="add-field btn btn-primary">Add field</button>
<button type="submit" name="uploadreport" value="uploadreport" class="btn  btn-outline-primary">Submit</button>
  </div>
  
</form>


<script>

$('.multi-field-wrapper').each(function() {
    var $wrapper = $('.multi-fields', this);
    $(".add-field", $(this)).click(function(e) {
        $('.multi-field:first-child', $wrapper).clone(true).appendTo($wrapper).find('input').val('').focus();
    });
    $('.multi-field .remove-field', $wrapper).click(function() {
        if ($('.multi-field', $wrapper).length > 1)
            $(this).parent('.multi-field').remove();
    });
});


$(document).on("click", ".browse", function() {
  var file = $(this)
    .parent()
    .parent()
    .parent()
    .find(".file");
  file.trigger("click");
});
$(document).on("change", ".file", function() {
  $(this)
    .parent()
    .find(".form-control")
    .val(
      $(this)
        .val()
        .replace(/C:\\fakepath\\/i, "")
    );
});



</script>
<script>
$(function () {
  bsCustomFileInput.init();
});
</script>


Paste in Controller


<?php


$user_id = $this->session->userdata('user_id');
$doc_patients = $this->User_Model->get_single_appointments($appointment_id);
$Patient_id = $doc_patients[0]->uid;
//$json_arr = json_decode($Patient_his_titles, true);
//print_r($json_arr);
// die();
if($this->input->post('uploadreport')=='uploadreport' || $this->input->post('uploadprescription')=='uploadprescription' ){

$report_type = 'testreport';
$title = $this->input->post('title');
$files = $_FILES['report']['name'];
$total_reports = count($files);
  $file = array();
  $upload_name = array();
  $report_title = array();
for($i=0; $i<$total_reports; $i++){
//echo $i.'jassi <br>';
$report_name = $title[$i];
$file_name = $_FILES['report']['name'][$i];
if(!empty($file_name) || !empty($report_name)){
$_FILES['file']['name'] = $_FILES['report']['name'][$i];
$_FILES['file']['type'] = $_FILES['report']['type'][$i];
$_FILES['file']['tmp_name'] = $_FILES['report']['tmp_name'][$i];
$_FILES['file']['error'] = $_FILES['report']['error'][$i];
$_FILES['file']['size'] = $_FILES['report']['size'][$i];
  
$config['upload_path']          = 'assets/new-template/patient-reports';
//$config['allowed_types']        = '*';
$config['allowed_types']        = 'docx|doc|DOC|DOCX|rtf|pdf|gif|jpg|png|jpeg';
//$config['max_width']            = 128;
//$config['max_height']           = 128;
$config['encrypt_name']         = TRUE;
$this->load->library('upload', $config);


if ( ! $this->upload->do_upload('file'))
{
$error = $this->upload->display_errors();

else

$data = array('upload_data' => $this->upload->data());
$upload_name[] = $this->upload->data('file_name');
$report_title[] = $report_name;
}  

}
}
 
$title = $report_title;
$files = $upload_name;
if($total_reports==$i){
 
$patient_history = $this->User_Model->patient_reports($appointment_id,$user_id,$report_type);

if(count($patient_history)>0){
$Patient_his_id = $patient_history[0]->id;
$Patient_his_titles = $patient_history[0]->title;
$Patient_his_reports = $patient_history[0]->doc;
$oldtitle = json_decode($Patient_his_titles,true);
$oldreport = json_decode($Patient_his_reports,true);
$titleresult = array_merge($title, $oldtitle);
$filesresult = array_merge($files, $oldreport);
$newtitle = json_encode($titleresult);
$newreport = json_encode($filesresult);

$data = array(
'title' => $newtitle,
'doc' => $newreport
);

$update = $this->User_Model->update_patient_report($data,$Patient_his_id);
}
else{
$titles = json_encode($title);
$reports = json_encode($files);
$data = array(
'appointment_id' => $appointment_id,
'doc_id' => $user_id,
'Patient_id' => $Patient_id,
'title' => $titles,
'doc' => $reports,
'type' => $report_type,
'status' => 1
);
$update = $this->User_Model->insert_patient_report($data);
}
if($this->db->affected_rows()){
$this->session->set_flashdata('success', 'The report has been updated successfully.');
header('Location: ' . $_SERVER['HTTP_REFERER']);
}
//die();
}
?>


In Model

Create function according to you.

27 April 2021

How to Create "Google Login" in Codeigniter?

Google Login Integration in Codeigniter






Paste in Controller




$uuser_id = '';
include_once(FCPATH.'googlelogin-library/vendor/autoload.php');

$google_client = new Google_Client();

$google_client->setClientId('975330128814-il47gqr1l99uleblged7altinhpm99g3.apps.googleusercontent.com'); //Define your ClientID

$google_client->setClientSecret('c-6xwtqoC4DRXV_blQ9QB6Lu'); //Define your Client Secret Key

$google_client->setRedirectUri(base_url().'login'); //Define your Redirect Uri
$google_client->addScope('email');

$google_client->addScope('profile');
 
//echo '<pre>'; 
// print_r($google_client);
//echo $_GET["code"];
  if(isset($_GET["code"]))
  {


   $token = $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);

   if(!isset($token["error"]))
   {
$google_client->setAccessToken($token['access_token']);

$this->session->set_userdata('access_token', $token['access_token']);

$google_service = new Google_Service_Oauth2($google_client);

$data = $google_service->userinfo->get();

$current_datetime = date('Y-m-d H:i:s');

if(count($this->User_Model->check_google_account_exists($data['id']))>0)
{
//update data 
$user_data = array(
  'name' => $data['given_name'],
  'lastname'  => $data['family_name'],
  'email' => $data['email'],
);

// $this->User_Model->update_google($user_data, $data['id']);
$googleresult = $this->User_Model-> google_login($data['email'], $data['id']);
$uuser_id = $googleresult[0]->id;
}
else
{
if(count($this->User_Model->get_email_data($data['email']))>0){
$this->session->set_flashdata('login_failed', 'This email is already registered.');
redirect('login');
}
else{
$user_data = array(
  'google_id' => $data['id'],
  'name'  => $data['given_name'],
  'lastname'   => $data['family_name'],
  'email'  => $data['email'],
  'role'  => 'employee'

);
$uuser_id = $this->User_Model->googleregistation($user_data);
}



$user_detail = $this->User_Model->get_single_user($uuser_id);
//echo count($user_detail);
//print_r($user_detail);
if (count($user_detail) > 0) {
//Create Session
$user_data = array(
'full_user_detail' => $user_detail,
'user_id' => $user_detail[0]->id,
'email' => $user_detail[0]->email,
'role' => $user_detail[0]->role,
'username' => $user_detail[0]->name.' '.$user_detail[0]->lastname,
'is_user_login' => true
);
 
$set_session = $this->session->set_userdata($user_data);
$this->session->set_flashdata('user_loggedin', 'You are now logged in.');
redirect('users/dashboard'); 
}
else{
$this->session->set_flashdata('login_failed', 'Login is invalid.');
redirect('login');
}
   }
  } 
  
  $login_button = '';
  if(!$this->session->userdata('is_user_login'))
  {
   $login_button = $google_client->createAuthUrl();
//echo $login_button;
//   die();
   $data['login_button'] = $login_button;
  }

$this->load->view('users/login', $data);



Model  in Controller


public function get_single_user($id){
$this->db->select("*"); 
$this->db->from('users');
$this->db->where('id', $id);
$query = $this->db->get();
return $query->result();
}


/*========================================Google Account=========================================*/

public function update_google($data,$user_id){
$this->db->where('google_id', $user_id);
return $this->db->update('users', $data);
}


// Check email exists
public function check_google_account_exists($google_id){
$this->db->select("*"); 
$this->db->from('users');
$this->db->where('google_id', $google_id);
$query = $this->db->get();
return $query->result();
}
public function googleregistation($userdata){
$this->db->insert('users', $userdata);
return $insertId = $this->db->insert_id();
}
public function google_login($email, $google_id){
//Validate
$this->db->select("*"); 
$this->db->from('users');
$this->db->where('email', $email);
$this->db->where('google_id', $google_id);
//$this->db->where("(role='employee' OR role='employer')", NULL, FALSE);
$query = $this->db->get();
return $query->result();
}


View in Controller

<a href="<?php if(!empty($login_button)){ echo $login_button; } ?>" >Login with Google</a>

26 April 2021

How to remove index.php from URL in Codeigniter?

Remove index.php from URL in Codeigniter?


RewriteEngine On
RewriteCond $1 !^(index\.php|assets|images|js|css|uploads|favicon.png)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L]

How to fix font-awesome icons from error (has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.).

Fix font-awesome icons from error (has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.).

Paste in htaccess file    

<IfModule mod_headers.c>
  <FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css|css)$">
    Header set Access-Control-Allow-Origin "*"
  </FilesMatch>
</IfModule>

22 April 2021

How to create forgot password page with ajax in Codeigniter?

Create forgot password page with ajax in Codeigniter



Forgot Password




Paste in view file


<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>AdminLTE 3 | Forgot Password</title>

  <!-- Google Font: Source Sans Pro -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="<?php echo base_url().'assets/new-template/'; ?>plugins/fontawesome-free/css/all.min.css">
  <!-- icheck bootstrap -->
  <link rel="stylesheet" href="<?php echo base_url().'assets/new-template/'; ?>plugins/icheck-bootstrap/icheck-bootstrap.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="<?php echo base_url().'assets/new-template/'; ?>dist/css/adminlte.min.css">
  
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css">
  
  
  <style> 
.red_error {
    color: red;
    display: block;
    width: 100% !important;
    font-size: 19px;
}

.success_error {
    color: green;
    display: block;
    width: 100% !important;
    font-size: 19px;
}

.loader {
    border: 5px solid #cacaca;
    border-radius: 50%;
    border-top: 5px solid #141B78;
    border-bottom: 5px solid #141B78;
    width: 25px;
    height: 25px;
    -webkit-animation: spin 2s linear infinite;
    animation: spin 2s linear infinite;
}
.preloader_box {
    position: absolute;
    width: 100%;
    background: #a2a2a280;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 9999999;
    justify-content: center;
    text-align: center;
    align-items: center;
display:none;
}
.loader {
    border: 7px solid #717171;
    border-radius: 50%;
    border-top: 7px solid #141B78;
    border-bottom: 7px solid #141B78;
    width: 40px;
    height: 40px;
    -webkit-animation: spin 2s linear infinite;
    animation: spin 2s linear infinite;
}
@-webkit-keyframes spin {
  0% { -webkit-transform: rotate(0deg); }
  100% { -webkit-transform: rotate(360deg); }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
  </style>
  
</head>





<body class="hold-transition login-page">
<div class="login-box">
  <div class="login-logo">
    <a href="<?php echo base_url(); ?>"><b>Skill</b>Stadium</a>
  </div>
  <!-- /.login-logo -->
  <div class="card">
  <div class="preloader_box"><div class="loader"></div></div>
    <div class="card-body login-card-body">
      <p class="login-box-msg">You forgot your password? Here you can easily retrieve a new password.</p>

      <form id="forget_password"  action=""  method="post">
        <div class="input-group mb-3">
          <input type="email" class="form-control" name="email" placeholder="Email" required>
          <div class="input-group-append">
            <div class="input-group-text">
              <span class="fas fa-envelope"></span>
            </div>
          </div>
  <div class="email_error red_error"></div>
  <div class="success"></div>
        </div>
        <div class="row">
          <div class="col-12">
            <button type="submit" class="btn btn-primary btn-block">Request new password</button>
          </div>
          <!-- /.col -->
        </div>
      </form>

      <p class="mt-3 mb-1">
        <a href="<?php echo base_url().'login'; ?>">Login</a>
      </p>
      <p class="mb-0">
        <a href="<?php echo base_url().'register'; ?>" class="text-center">Register a new membership</a>
      </p>
    </div>
    <!-- /.login-card-body -->
  </div>
</div>
<!-- /.login-box -->

<!-- jQuery -->
<script src="<?php echo base_url().'assets/new-template/'; ?>plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="<?php echo base_url().'assets/new-template/'; ?>plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- AdminLTE App -->
<script src="<?php echo base_url().'assets/new-template/'; ?>dist/js/adminlte.min.js"></script>

<script>
jQuery(document).ready(function($){
$("#forget_password").submit(function(e) {
e.preventDefault(); // avoid to execute the actual submit of the form.
$('.preloader_box').css('display','flex');
var form = $('#forget_password').serialize();

$.ajax({
type: "POST",
url: '<?php echo base_url();?>userlogin/forget_password_mail',
data: form, // serializes the form's elements.
dataType: "JSON",
success: function(data)
{
// var result = $.parseJSON(data);
console.log(data);
if(data['email_error'] != ''){
$('.email_error').html(data['email_error']);
}
else{
$('.email_error').html('');
}
if(data['success'] != '' && data['status'] == 1){
$('#forget_password').html('<div class="input-group mb-3"><input type="text" class="form-control opt" name="opt" placeholder="Enter Otp"><div class="input-group-append"><div class="input-group-text"><span class="fas fa-envelope"></span></div></div><div class="otp_error red_error"></div></div><div class="row"><div class="col-12"><button type="submit" name="otp_bt" class="btn btn-primary btn-block otp_bt">Continue</button></div></div>');
$('.success').html(data['success']);
$('.email_error').html('');
}
else{
$('.success').html('');
$('.preloader_box').css('display','none');
}
}); 
});
$(document).on('click','.otp_bt',function(e) {
e.preventDefault(); // avoid to execute the actual submit of the form.
$('.preloader_box').css('display','flex');
var form = $('#forget_password').serialize();

$.ajax({
type: "POST",
url: '<?php echo base_url();?>userlogin/otp_verification',
data: form, // serializes the form's elements.
dataType: "JSON",
success: function(data)
{
// var result = $.parseJSON(data);
console.log(data);
if(data['otp_error'] != ''){
$('.otp_error').html(data['otp_error']);
}
else{
$('.otp_error').html('');
}
if(data['status'] != '' && data['status'] == 1){
$('#forget_password').html('<div class="input-group mb-3"><input type="text" class="form-control pass" name="pass" placeholder="Enter Password"><div class="input-group-append"><div class="input-group-text"><span class="fas fa-envelope"></span></div></div></div><div class="input-group mb-3"><input type="text" class="form-control confirm_pass" name="confirm_pass" placeholder="Enter Confirm Password"><div class="input-group-append"><div class="input-group-text"><span class="fas fa-envelope"></span></div></div><div class="password_error red_error"></div></div><div class="row"><div class="col-12"><button type="submit" name="sub_password" class="btn btn-primary btn-block sub_password">Submit</button></div></div>');
$('.success').html(data['success']);
$('.otp_error').html('');
}
$('.preloader_box').css('display','none');
}
}); 
});
$(document).on('click','.sub_password',function(e) {
e.preventDefault(); // avoid to execute the actual submit of the form.
$('.preloader_box').css('display','flex');
var form = $('#forget_password').serialize();

$.ajax({
type: "POST",
url: '<?php echo base_url();?>userlogin/change_otp_password',
data: form, // serializes the form's elements.
dataType: "JSON",
success: function(data)
{
// var result = $.parseJSON(data);
console.log(data);
if(data['password_error'] != ''){
$('.password_error').html(data['password_error']);
}
else{
$('.password_error').html('');
}
if(data['status'] != '' && data['status'] == 1){
 
swal("Success", "Well done, Your password has been changed successfully.", "success")
$('#forget_password').html('<div class="success_error">Your password has been changed successfully.</div>');
//$('.success').html(data['success']);
$('.password_error').html('');
}
$('.preloader_box').css('display','none');
}
}); 
}); 
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>
</body>
</html>


Controller in view file


/*=================================Forget Password=========================================*/


public function send_mail($to_email,$message) { $from_email = "skillstadium@gmail.com"; // $to_email = $this->input->post('email'); //Load email library $this->load->library('email'); $this->email->from($from_email, 'SkillStadium'); $this->email->to($to_email); $this->email->set_mailtype("html"); $this->email->subject('SkillStadium'); $this->email->message($message); //Send mail if($this->email->send()){ // $this->session->set_flashdata("email_sent","Congragulation Email Send Successfully."); return true; } else{ // $this->session->set_flashdata("email_sent","You have encountered an error"); // $this->load->view('contact_email_form'); return false; } }

public function forget_password($page = 'forget-password'){
$data['title'] = ucfirst($page);
$this->load->view('users/forget-password');
}
public function random_number(){
$ran_num = rand(9999,99999);
return $ran_num;
}
//forget password functions start
public function forget_password_mail(){
$email = $this->input->post('email');
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div class="red_error">', '</div>');
$this->form_validation->set_rules('email', 'Email', 'required|trim|xss_clean|callback_email_exists'); 
$error_array = array();
        if ($this->form_validation->run() == FALSE) { 
$error_array['email_error'] = form_error('email');
        } 
        else { 
 
  $result = $this->User_Model->get_email_data($email);
$per_id = $result[0]->id;
$random_number = $this->random_number();
        $this->load->helper('cookie');
$set_cookies = setcookie("optcode", $random_number, time() + (60 * 5)); //5min
$set_user_id_cookies = setcookie("per_id", $per_id, time() + (60 * 5)); //5min
if($set_cookies && $set_user_id_cookies){
$message = $random_number.' OTP is valid for 5 min... ';
$mail = $this->send_mail($email,$message);
if($mail){
$error_array['success'] = 'Check E-mail for OTP';
$error_array['status'] = 1;
}
}
}
echo json_encode($error_array);    
 }


 //forget password functions start
public function otp_verification(){
$otp = $this->input->post('opt');
$this->load->library('form_validation'); 
$error_array = array();
        if ($_COOKIE['optcode'] != $otp) {
$error_array['otp_error'] = 'Invalid Otp';
        } 
        else{
$error_array['status'] = 1;
}
echo json_encode($error_array);    
}



 public function change_otp_password(){
$pass = $this->input->post('pass');
$confirm_pass = $this->input->post('confirm_pass');
$encrypt_password = md5($pass);
$user_id = $_COOKIE['per_id'];
$error_array = array();
if(empty($pass)){
$error_array['password_error'] = 'Password field is required';
}
elseif(empty($confirm_pass)){
$error_array['password_error'] = 'Confirm Password field is required';
}
elseif($pass != $confirm_pass) {
$error_array['password_error'] = 'Confirm Password is not matched';
        } 
        else { 
$data = array(
'password' => $encrypt_password
);
$this->User_Model->update_user($data,$user_id);
$error_array['status'] = 1;
}
echo json_encode($error_array);    
 }
// Check Email exists
public function email_exists($email){
$this->form_validation->set_message('email_exists', 'This email is not exits.');
if ($this->User_Model->check_email_exists($email)) {
return false;
}
else{
return true;
}
}


Paste in Model file....


// Check email exists
public function check_email_exists($email){
$query = $this->db->get_where('users', array('email' => $email));

if(empty($query->row_array())){
return true;
}else{
return false;
}
}
public function update_user($data,$user_id){
$this->db->where('id', $user_id);
return $this->db->update('users', $data);
}
public function get_email_data($email){
$this->db->select("*"); 
$this->db->from('users');
$this->db->where('email', $email);
$query = $this->db->get();
return $query->result();
}

How to create video slider with cuncks of videos without download all videos?

 Create video slider with cuncks of videos without download all videos function custom_video_slider_shortcode() { $slider_id = 'vide...