hi coders..

i need live availability code

i am using codeigniter. i am inserting values(username,password,email,phone number) by using array .

if the email is already in databse i need to show error message..

with out reloading the page....

thanks in advance.

Recommended Answers

All 4 Replies

You will need to use JavaScript and ajax.
First you should create a php page that will return true or false for the values you are testing.

e.g. yourwebsite.com/ajax/checkemail.php?email=someone@somewhere.com

When you have done this your main page will use JavaScript to call the ajax page with the user input and update the main page depending on the result.

thanks paulkd..!

can u please suggest me how to use ajax in my javascript.

the below code for validation let me know how to cal ajax hear...

if(Pemail == "" || !Pemail.match(emailReg)){
            $("#ePemail").html("Please enter email");
            $("#Pemail").focus();

            }

Although I've not tested this..
Your ajax php page should query the database for the supplied email address and return json_encode(true) if the email address is already used and return json_encode(false) if not.

Your form will use the following (untested) jQuery:-

$(document).ready(function(){

    //default form not submitted
    $("#submit-button").data("submitted",false);    

    //prevent enter key in input field from submitting form
    $("#your-form").on("submit",function(e){
        if($("#submit-button").data("submitted")===false) {
            e.preventDefault();
        }
    });

    //trigger form submission
    $("#submit-button").on("click",function(){
        checkEmail();
    });

});


function checkEmail()
{
    $.ajax({
        type : "GET",
        url: '/path/to/your/ajax/checkemail.php',
        dataType: "json",
        data: ({
            email: $("#email").val()
        }),
        success: function(emailExists)
        {
            if(emailExists) {
                alert("email already exists");
            } else {
                $("#submit-button").data("submitted",true);
                $("#your-form").submit();
            }
        }
    });             
}

My example shows three css ids: your-form for the <form id= tag, submit-button for the <input type="submit... tag and email for your user's email input field. You will need to substitute your own.

First thing to do is create and test your ajax page without using JavaScript - simply call the page as previously mentioned and output the word true or false.

thanks for suggestion

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.