12 March 2021

How to keep the current tab active on page reload?

 keep the current tab active on page reload


<script>

jQuery(window).load(function() {

    // this will get the full URL at the address bar

    var url = window.location.href; 


    // passes on every "a" tag 

    jQuery(".menuuuu a").each(function() {

            // checks if its the same on the address bar

        if(url == (this.href)) { 

            jQuery(this).closest("li").addClass("active");

        }

    });

    });


</script>


In html

<div class="menuuuu">

<ul class="nav-list1">

<li  class=""><a href="<?php echo site_url().'/dashboard/'; ?>"><i class="side-menu__icon fas fa-tachometer-alt"></i> Dashboard</a> </li>

<li><a href="<?php echo site_url().'/profile/'; ?>"><i class="side-menu__icon fas fa-user"></i> My Profile</a></li> 

<!-- <a href="#"><li><i class="side-menu__icon far fa-user"></i> Available Courses</li></a>   -->

<li><a href="<?php echo site_url().'/scholarship/'; ?>"><i class="side-menu__icon fas fa-graduation-cap"></i> About Scholarship</a></li> 

<li><a href="<?php echo site_url().'/scholarship-exam/'; ?>"><i class="side-menu__icon fas fa-chalkboard"></i> Scholarship Exam</a> </li>

<li><a href="<?php echo site_url().'/contact/'; ?>"><i class="side-menu__icon fas fa-phone-square-alt"></i> Contact Us</a> </li>

</ul>

</div>

09 March 2021

How to create forget password with otp in wordpress without plugin?

Create forget password with otp in wordpress without plugin.


 Main-Page


<?php

 /* Template Name: forget-password  */

 ob_start();

get_header();

?>


<div id="primary" class="content-area">

                <main id="main" class="site-main" role="main">

                                <?php

                                // Start the loop.

                                while ( have_posts() ) : the_post();

                                                // Include the page content template.

                                                get_template_part( 'template-parts/content', 'page' );

                                                // If comments are open or we have at least one comment, load up the comment template.

                                                if ( comments_open() || get_comments_number() ) {

                                                                comments_template();

                                                }

                                                // End of the loop.

                                endwhile;

                                ?>

                </main><!-- .site-main -->

           

</div><!-- .content-area -->

 




<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css">


<style>


.red_error{

color:REd;

}

</style>


<input type="hidden" name="user_id" class="user_id" val=''>

<form name="lostpasswordform" id="lostpasswordform" class="lostpasswordform" method="post">

<input type="email" name="email" class="email" placeholder="Email">

<div class="email_error red_error"></div>

<input type="tel" name="phone" class="phone" placeholder="Phone">

<div class="phone_error red_error"></div>

<input type="submit" name="forget_pass" class="forget_pass" value="Continue">


</form>


<?php


//echo get_option('admin_email');

?>


<script>

jQuery(document).ready(function($){

 

jQuery('.forget_pass').click(function(e) {

event.preventDefault()

var email = $('.email').val();

var phone = $('.phone').val();

if(email==''){

$('.email_error').html('Email field is required');

     return false;

    

     }

else{

$('.email_error').html(''); 

}

     if(phone==''){


$('.phone_error').html('Phone field is required');

     return false;

    

     }

else{

$('.phone_error').html('');

}

 

//alert(email+phone);

//var ajax = "http://wpcodekit.com/wp-admin/admin-ajax.php";

var ajax =  "<?php echo admin_url('admin-ajax.php'); ?>";


    var data = {

    'action' : "forget_password",

    'email': email,

    'phone' : phone

    }



     $.post(ajax,data,function(response){

    // console.log(response);

    // location.reload(true);

var result = $.parseJSON(response);


if(result[0] != ''){

$('.email_error').html(result[0]);

}

else{

$('.email_error').html('');

}

if(result[1] !=''){

$('.phone_error').html(result[1]);

}

else{

$('.phone_error').html('');

}

if(result[2]==1){

$('.lostpasswordform').html('<input type="text" name="opt" class="opt" placeholder="Enter Otp"><div class="otp_error red_error"></div><input type="submit" name="otp_bt" class="otp_bt" value="Continue">');

$('.user_id').val(result[3]);

}

else{

//$('.email_error').html('');

//$('.phone_error').html('');

}

//console.log(result[2]);

     });

});




jQuery(document).on('click','.otp_bt',function(e) {

e.preventDefault();

var otp = $('.opt').val();


if(otp==''){


$('.otp_error').html('OTP is required');

     return false;

    

     }

else{

$('.otp_error').html('');

}


 

//var ajax = "http://wpcodekit.com/wp-admin/admin-ajax.php";

var ajax =  "<?php echo admin_url('admin-ajax.php'); ?>";

    var data = {

    'action' : "check_otp",

    'otp': otp

    }


    $.post(ajax,data,function(response){

    //console.log(response);

    // location.reload(true);

  var result = $.parseJSON(response);

if(result[0] == 1){

$('.lostpasswordform').html('<input type="password" name="password" class="password" placeholder="New Password"><div class="password_error red_error"></div><input type="password" name="confirm_pass" class="confirm_pass" placeholder="Confirm New Password"><div class="confirm_error red_error"></div><input type="submit" name="sub_pass" class="sub_pass" value="Continue">');

$('.otp_error').html('');

}

else{

$('.otp_error').html(result[0]);

}


     });

});





jQuery(document).on('click','.sub_pass',function(e) {

e.preventDefault();

var password = $('.password').val();

var confirm_pass = $('.confirm_pass').val();

var user_id = $('.user_id').val();


if(password==''){

$('.password_error').html('Password is required');

     return false;

    

     }

else{

$('.password_error').html('');

}

 

if(confirm_pass==''){

$('.confirm_error').html('Confirm Password is required');

     return false;

    

     }

else{

$('.confirm_error').html(''); 

}


if(password!=confirm_pass){

$('.confirm_error').html('confirm password does not match');

return false;

     }

else{

$('.confirm_error').html('');

}


var ajax =  "<?php echo admin_url('admin-ajax.php'); ?>";


    var data = {

    'action' : "set_password",

    'password': password,

    'confirm_pass': confirm_pass,

    'user_id': user_id

    }


    $.post(ajax,data,function(response){

    //console.log(response);

    // location.reload(true);

  var result = $.parseJSON(response);

if(result[0] == 1){

$('.otp_error').html('');

swal("Success", "Well done, your password has been updated", "success")

}

else{


$('.confirm_error').html(result[0]);

}


     });

});

});


</script>


<?php 


get_footer(); 


?>



Paste in function.php



function send_mail($email,$message){


//php mailer variables

  $to = $email;

  $from = get_option('admin_email');

  $subject = "Otp";

  $headers = 'From: '. $from . "\r\n" .

    'Reply-To: ' . $from . "\r\n";

 


//Here put your Validation and send mail

$sent = wp_mail($to, $subject, strip_tags($message), $headers);


      if($sent) {

//echo 'email has been sent.';

      }//message sent!

      else  {

//echo 'Error';

      }//message wasn't sent

  

}



 function forget_password(){

 

ob_start();

$user_id;

$success_status = 0; 

if(function_exists('date_default_timezone_set')) {

date_default_timezone_set("Asia/Kolkata");

}

$date = date("d/m/Y");

$date1 =  date("H:i a");

$phone = $_POST['phone'];

$email = $_POST['email'];

global $wpdb;


if(!email_exists($email)){

$error_email = 'Email does not match, please recheck and try again';

$email_status = 0;

}

else{

$email_status = 1;

$error_email = '';

}


if($email_status == 0){

$error_phone = '';

$success_status = 0;

}

else{


$user = get_user_by('email',$email);

$user_id = $user->ID;


$havemobile = get_user_meta($user_id,'phone_no',$phone); // stores the value of logged in user's meta data for 'test'.


if ($havemobile==$phone){

   $error_phone = '';

else {

     $error_phone = 'Mobile does not match, please recheck and try again';

//die();

}


if(email_exists($email) && $havemobile==$phone){

$random_result = rand(10000,99999);

setcookie("forget_password_coo", $random_result, time() + (60 * 5)); //5min

send_mail($email,$random_result.' Valid OTP for 5-Min');

//echo $_COOKIE['forget_password_coo'].'jassi';

$success_status = 1; 

}

}

echo json_encode(array($error_email,$error_phone,$success_status,$user_id));

die();

//ob_end_clean();

 }


 add_action('wp_ajax_nopriv_forget_password','forget_password');

 add_action('wp_ajax_forget_password','forget_password');





 function check_otp(){

 

ob_start(); 

$otp = $_POST['otp'];

global $wpdb;

if($_COOKIE['forget_password_coo']==$otp){

//$otp_status = 'true';

$otp_status = 1;

}

else{

$otp_status = 'Please enter valid OTP';

}

echo json_encode(array($otp_status));

die();

//ob_end_clean();

 }


 add_action('wp_ajax_nopriv_check_otp','check_otp');

 add_action('wp_ajax_check_otp','check_otp');

 

 

 

 function set_password(){

 

ob_start(); 

$password = $_POST['password'];

$confirm_pass = $_POST['confirm_pass'];

$user_id = $_POST['user_id'];

global $wpdb;

if(!empty($user_id) && !empty($password)){

wp_set_password( $password, $user_id );

$password_status = 1;

}

else{

$password_status = 'error';

}


echo json_encode(array($password_status));

die();


 }


 add_action('wp_ajax_nopriv_set_password','set_password');

 add_action('wp_ajax_set_password','set_password');



06 March 2021

How to upload file in database with ajax in codeigniter?

Upload file in the database with ajax in Codeigniter?



Paste in View


<form id="doc_table" name="doc_table" method="post" enctype="multipart/form-data"   >
<?php //echo validation_errors(); ?> 
<?php //echo form_open_multipart('upload/do_upload'); ?>
      <div class="modal-body">
        
  <div class="form-group">
<label for="formGroupExampleInput">Document Name</label>
<input type="text" class="form-control doc_name" id="formGroupExampleInput" name="doc_name"  placeholder="Example input">
<label for="exampleFormControlTextarea1">Comment</label>
<textarea class="form-control doc_comment" id="exampleFormControlTextarea1" name="doc_comment"  rows="3"></textarea>
<label for="exampleFormControlFile1">Upload File</label>
<input type="text" name="lead_id" value="<?php echo $leads[0]['id']; ?>">
<input type="file" class="form-control-file doc_file" name="doc_file"  id="exampleFormControlFile1">
  </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
        <input type="submit" value="Save" name="upload_documents" class="lead_upload_docs" class="btn btn-primary">
      </div>
  </form>


<script>



jQuery('#doc_table').submit(function(e){
e.preventDefault();
 
var doc_name = jQuery('.doc_name').val();
var doc_comment = jQuery('.doc_comment').val();
var doc_file = jQuery('.doc_file').val();
var leadid =  <?php echo $leads[0]['id']; ?>;


if(leadid){
jQuery.ajax({
url:'<?php echo base_url(); ?>leads/add_lead_docs',
type:"post",
data:new FormData(this),
processData:false,
contentType:false,
cache:false,
async:false,
success:function(response){  
console.log(response);
}
});

}else{
jQuery('#result_notice').html('');
}
  
});

</script>




Paste in Controller




  public function add_lead_docs(){
  


$lead_id = $this->input->post('lead_id');
$doc_name = $this->input->post('doc_name');
$doc_comment = $this->input->post('doc_comment');
$config['upload_path']          = 'assets/upload';
            $config['allowed_types']        = 'gif|jpg|png';
$config['encrypt_name'] = TRUE;
                $this->load->library('upload', $config);
                if ( ! $this->upload->do_upload('doc_file'))
                {
                        $error = array('error' => $this->upload->display_errors());
print_r($error);
echo 'FIle Error';
                }
                else
                {

                        $data = array('upload_data' => $this->upload->data());
echo 'FIle Uploaded Successfully';
echo $file_name = $this->upload->data('file_name');
                } 
$data = array(
                    'doc_name' => $doc_name,
                    'doc_comment' => $doc_comment,
                    'doc_path' => $file_name,
'p_id' => $lead_id,
                    'type' => 'doc'
); 
    $this->Leads_model ->add_documents($data); 
 
  
  }




Paste in Model

function add_documents($data)
    {
$insert = $this->db->insert('leads_history', $data);
$insert_id=$this->db->insert_id();
return $insert_id;
}

How to create multi step form with validations?

Create multi step form with validations  <!DOCTYPE html> <html lang="en"> <head>   <meta charset="UTF-8...