既不需要也没有模式在html中工作

时间:2017-07-24 11:04:33

标签: php jquery html ajax

我正在尝试通过使用required和pattern关键字验证手机号码,电子邮件,名字等字段,但它没有响应任何内容。

在我的程序中,如果用户输入了未存储在数据库中的手机号码,则有一个输入字段用于手机号码,然后弹出注册页面,用户应注册进一步处理,如果他们输入了存储在数据库中的手机号码然后显示随机数,但是当我在注册表单中输入值但是没有验证时,我在输入字段中返回了必需的关键字,但仍然没有响应。

请帮我解决这个问题。

我们的代码:

HTML

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>

<!DOCTYPE html>
<body>
<div>           
<form  action = "#" method = "post" >
    <div>
    <legend >Login</legend>
        <table  id="verify_table" cellpadding="2" cellspacing="2" >
            <tr>
            <td> Mobile No. </td>
            <td><input id="mob" type="tel"  name="mobile" required pattern="\[7-9]{1}[0-9]{9}\" /></td>
            <td><input type="button" name="verify" class="verify" value="Verify"></td>
            </tr>
        </table>                
    </div>  
<div id="random" style="display: none;" >
    <table id='random_table'>
    <tr>
    <td>Random Number generated</td>
    <td id='rand'>
    </tr>
    </table>
</div>          
<!--Register pop up-->

    <div id="reg_light" class="white_content">
        <div id="register-title">
            <div id="reg-title">
                <h6>Register</h6>
            </div>
            <div id="close">
                <a href="javascript:void(0)" onclick="document.getElementById('reg_light').style.display='none';
                document.getElementById('fade').style.display='none'; $('#firstname').val('');
                                $('#lastname').val('');
                                $('#mobile_number').val('');
                                $('#email').val('');">X</a>
            </div>
        </div>  
        <?php  //echo form_open('register'); ?>

            <div id="register-inner">
                <form id="reg_form" method="POST">
                <table id="register_table">
                    <tr><td><font color="red">* Fields are mandatory</font></td></tr>
                    <!--<form id="reg_form" onSubmit="return formValidation();">-->
                        <tr>
                            <table id="name">
                                <tr>
                                    <td>First Name<font color="red">*</font></td>

                                    <td><input id="firstname" type="text" placeholder="First Name" name="firstname" required pattern="[A-Za-z]+" ></td>
                                    <td>Last Name<font color="red" >*</font></td>

                                    <td> <input id="lastname" type="text" placeholder="Last Name" name="lastname" required pattern="[A-Za-z]+"></td>
                                </tr>
                            </table>
                        </tr>
                        <tr><td>&nbsp&nbsp</td></tr>
                        <tr>
                            <table id="gen">
                                <tr>
                                    <td>Gender<font color="red">*</font></td>

                                    <td><input type="radio" name="gender" value="Male"> Male</td>

                                    <td><input type="radio" name="gender" value="Female"> Female</td>
                                </tr>
                            </table>
                        </tr>

                        <tr>
                            <table id="mob">
                                <tr>
                                    <td>Mobile No.<font color="red">*</font></td>

                                    <td><input id="mobile_number" type="text" placeholder="Mobile number" name="mobile_number" required pattern="[7-9]{1}[0-9]{9}" /></td>

                                    <td>Email id<font color="red">*</font></td>

                                    <td> <input id="email" type="email" placeholder="Email-id" name="email" required pattern="[A-Za-z]+[0-9]+@[A-Za-z]+.[A-Za-z]+"> </td>
                                </tr>
                            </table>

                            <table id="submit">
                                <tr>
                                    <td id="errorBox"></td>
                                    <td><input class="reg_data" id="submit" type="button" name="submit" value="Register"></td>
                                </tr>
                            </table>
                        </tr>
                </table>
                </form>
            </div>
</body>
</html>

这是我的jQuery代码

 $(document).ready( function() {    

        $('.verify').click(function(){
            var mob = $('#mob').val();
            //alert(mob);
                $.ajax({
                        url: "<?php echo base_url(); ?>/login/verify",
                        data: {'mob_no': mob},
                        type: "post",
                        cache: false,
                        success: function (data)
                        {
                            //alert(data);
                            var obj = $.parseJSON(data);
                            var fi="";
                            var otp="";
                            var rand="";
                            rand+=Math.floor(100000 + Math.random() * 99999);

                            $.each(obj, function()
                            {
                                fi=this['id'];

                            });

                            if(!fi=="")
                            {   
                                //document.getElementById("random").innerHTML=random_number;
                                $('#rand').val(rand);
                                document.getElementById("rand").innerHTML=rand;

                                document.getElementById('random').style.display='block';

                            }
                            else

                                document.getElementById('reg_light').style.display='block';
                                document.getElementById('fade').style.display='block';
                                    //alert(fi);

                            }
                        },
                        error: function (xhr, ajaxOptions, thrownError) {

                            //alert(thrownError);

                            }
                });
        });
    });

2 个答案:

答案 0 :(得分:0)

在使表单可见

后重置表单验证
 function resetFormValidator(formId) {
    $(formId).removeData('validator');
    $(formId).removeData('unobtrusiveValidation');
    $.validator.unobtrusive.parse(formId);
 }

答案 1 :(得分:0)

对于动态创建的dom 使用

args := make([]interface{}, 0, len(e.MapData) * 2 + 1)
args = append(args, e.Key)
for k, v := range e.MapData {
    args = append(args, k, v)
}
_,err := redis.StringMap(client.Do("HMSET", args...))