Home Registration form [VALIADTION IS NOT WORKING]
Reply: 0

Registration form [VALIADTION IS NOT WORKING]

user8699
1#
user8699 Published in April 19, 2018, 10:00 am
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" class="regform" method="post" name="reg_form" id="reg_form" onsubmit="return formValidation()">
                        <h2 class="text-center" style="color: #1d1d1d; font-size: 26px; font-weight: normal;">Registration <span style="color: #971233; font-size: 26px; font-weight: normal;">Form</span></h2> 
                        <hr style="border: 1px solid #971233;">
                        <div class="form-row">
                            <div style">* Indicates required field</div>
                            <div class="form-group col-sm-9">
                                <label class="font-color" for="name2">Name*</label>
                                <input type="text" class="form-control regborder" name="name" id="name" placeholder="Enter Your Full name">
                <span style="color: #FF0000;" id="nameError"></span>
                            </div>
                            <div class="form-group col-sm-9">
                                <label class="font-color" for="email2">Email*</label>
                                <input type="email" class="form-control regborder" name="email" id="email" placeholder="Enter Your Email Address">
                 <span style="color: #FF0000;" id="emailError"></span>
                            </div>
                            <div class="form-group col-sm-9">
                                <label class="font-color" for="Password1">Password*</label>
                                <input type="password" class="form-control regborder" name="password" id="password" placeholder="Enter Password Here">
                 <span style="color: #FF0000;" id="passwordError"></span>
                            </div>
                            <div class="form-group col-sm-9">
                                <label class="font-color" for="Re-type Password">Re-type Password*</label>
                                <input type="password" class="form-control regborder" name="cPassword" id="cPassword" placeholder="Re-enter Password Here">
                <span style="color: #FF0000;" id="cPasswordError"></span>
                            </div>
                            <div class="form-group col-sm-9">
                                <label class="font-color" for="Country">Country*</label>
                                <select class="form-control" id="country" name="country" style="width: 100%; padding: 8px; border: 0.5px solid #1D1D1D;">
                                    <option value="">-- Select Country --</option>
                    <?php
                    foreach ($countryArr as $key => $countryName) {
                    ?>
                        <option value="<?php echo $key; ?>"><?php echo $countryName; ?></option>
                    <?php
                    }
                    ?>
                                </select>
                <span style="color: #FF0000;" id="countryError"></span>
                            </div>
                            <!--Captcha Section-->
                            <div class="form-group col-sm-9">
                                <label class="sr-only" for="capBut"></label>
                                <table>
                                    <tr>
                                        <td>
                                            <input class="form-control" type="button" name="captcha" id="captcha" style="width:150px; height:40px; background-image:url(images/reload.png); color:#000; border:none; font-stretch:expanded; font-size:22px; font-weight:700;" disabled>
                                        </td>
                                        <td>&nbsp;&nbsp;
                                            <img src="images/reload.png" alt="Recaptcha" class="refresh" onClick="rand()" style="cursor: pointer; margin: 0 auto;" height="20" width="20">
                                        </td>
                                    </tr>
                                </table>
                                <input type="text" name="" class="form-control regborder" style="margin-top: 2%;" placeholder="Enter captcha here" required>  
                                <span style="color: #FF0000;" id="captchaError"></span>
                            </div>
                            <!--Captcha Section Ended-->
                            <div class="form-group col-sm-9">
                                <div class="text-center">
                    <br>
                                    <button type="submit" class="btn register" name="submit" id="submit">register</button>&nbsp;
                    <!--<button class="btn btn-block btn-primary" type="submit">Submit</button>-->
                                    <button type="reset" class="btn cancel">reset</button><span id="status"></span>
                                </div>
                            </div>
                        </div>
                    </form><script type="text/javascript">
        function validateCap()
        {
            var myForm = document.reg_form;
            if ((myForm.cap.value == "") || (myForm.cap.value != myForm.hid.value)) {
                alert("Enter the valid characters in the textbox provided!");
            }
        }
        function rand() {
            var chars = "0123456789";
            var string_length = 5;
            var randomstring = '';
            for (var i = 0; i < string_length; i++) {
                var rnum = Math.floor(Math.random() * chars.length);
                randomstring += chars.substring(rnum, rnum + 1);
            }
            var no = "0123456789";
            var rno = Math.floor(Math.random() * no.length);

            document.reg_form.captcha.value = randomstring;
            document.reg_form.captcha.style.backgroundImage = "url('images/reload_" + rno + ".png')";
        }
    </script>

    <!-- Form Validations Section -->

    <script type="text/javascript">
    function formValidation()
    {
    var name    = $('#name').val();
    var email       = $('#email').val();
    var password    = $('#password').val();
    var cPassword   = $('#cPassword').val();
    var country     = $('#country').val();
    var captcha     = $('#captcha').val();

    var flagname        = false;
    var emailFlag       = false;
    var passwordFlag    = false;
    var cPasswordFlag   = false;
    var countryFlag     = false;
    var captchaFlag     = false;

    //Name Validation
    if(name == "")
    {
        $("#nameError").text("*Please enter the fullname")
        flagname = true;
    }
    else
    {
        $("#nameError").text("Correct fullname");
    }

    //Password Validation
    if(password == "")
    {
        $("#passwordError").text("*Please enter the password");
        passwordFlag = true;
    }
    else
    {
        $("#passwordError").text("");
    }

    //Confirm Password Validation
    if(cPassword == "")
    {
        $("#cPasswordError").text("*Please re-enter the password");
        cPasswordFlag = true;
    }
    else
    {
        $("#cPasswordError").text("");
    }

    //Country Flag
    if(country == "")
    {
        $("#countryError").text("*Please select the country");
        countryFlag = true;
    }
    else
    {
        $("#countryError").text("");
    }

    //Captcha Validation
    if(name == "")
    {
        $("#captchaError").text("*Please enter the fullname")
        flagcaptcha = true;
    }
    else
    {        
        $("#captchaError").text("");
    }

    //Email Validation
    if(email == "")
    {
        $("#emailError").text("*Please enter the email");
        emailFlag = true;
    }
    else if(email!="")
    {
        var filter = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
        if (!filter.test(email)) 
        {          
        $("#emailError").text("*Please enter the valid email");
        emailFlag = true;
        }
        else
        {
        $("#emailError").text("");
        }
    }
    else
    {
        $("#emailError").text("");
    }
    }   

    </script>
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.574579 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO