Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Check duplicate email using Jquery validation in laravel

//html form
<form id="formId" method="post" action="url">
@csrf
<input type="email" id="email" name="email">
<button type="submit">Submit</button>
</form>

//jquery validation to check Duplicate Emails
//Dont't forget to include jqury and jquery.validation files or CDN
<script>
    $("#FormId").validate({
        rules:{
            email: {
                required: true,
                email:true,
                remote: 'check-duplicate-email'
            }
        },
        messages: {
            email: {
                required: "Email is required",
                email: "Valid Email Please",
                remote: "This Email Already Exists"
            }
        }
    });
<script>

//Route
Route::match(['get', 'post'], 'check-duplicate-email', [ControllerName::class, 'checkDuplicateEmail']);

//controller function
public function checkDuplicateEmail(Request $request){
        if($request->ajax()){
            $adminEmail = $request->email;
            $emailCount = ModelName::where('email', $adminEmail)->count();
            if($emailCount>0){
                echo "false";
            } else {
                echo "true";
            }
        }
    }
Comment

PREVIOUS NEXT
Code Example
Php :: get last two numbers from int php 
Php :: laravel middleware route group 
Php :: laravel get last 5 records 
Php :: wordpress debug true 
Php :: echo alert php 
Php :: laravel jetstream livewire 
Php :: In php, how to convert string value into an int 
Php :: php check if string email 
Php :: while loop in laravel 
Php :: laravel test specific class 
Php :: getting current timestamp in php 
Php :: how to debug php 
Php :: php change version linux 
Php :: collection pluck remove duplicates 
Php :: php validate phone number 
Php :: auto scroll down in javascript 
Php :: remove autoupdate wordpress 
Php :: add like and equal in same query in laravel 
Php :: how to mantain text in form after error php 
Php :: how to remove jstream package 
Php :: laravel Postcontroller.php 
Php :: php remove space before and after string 
Php :: php change an associative array into indexed array 
Php :: laravel blade auth check 
Php :: forward parameter from blade to another blade with filter 
Php :: laravel with trashed specific 
Php :: yii2 get cookie 
Php :: how to run a specific test in laravel 
Php :: send email when form is submitted php 
Php :: unique sql queries laravel 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =