-2

我有一个像这样的html表单..

<span id="langBrowser"></span>
    <table>
       <tr>
          <td id="sign_up" class="heading"></td>
              <td style="text-align:right">
                 <span class="close_font"><b>Close</b></span>&nbsp;<?php 

              echo CHtml::image(Yii::app()->baseUrl.'/images/close_icon.png',"",array('id'=>'close_reg_icon','style'=>'title:Advertisement;margin-top:5px;')); ?
          </td>
       </tr>
       <tr><td colspan="2" id="label1" class="sub_heading"></td></tr>
       <tr><td colspan="2"><hr/></td></tr>
       <tr>
          <td style="display:none" class="success" colspan="2" align="center">You are successfully registered in MyLokal Network, Please check your email for activating your account.</td>
       </tr>
       <tr><td>&nbsp;</td></tr>
   </table>
             <div id="success_hide">
                 <table>
        <tr>
            <td id="first_name_label_register" style="text-align:right;width:30%" class="label"></td>
            <td><?php echo $form->textField($model,'USR_FirstName',array('name'=>"first_name",'id'=>"first_name",'class' =>'inputtext')); ?></td>

        </tr>
        <tr>
            <td  id="last_name_label_register" style="text-align:right" class="label"></td>
            <td><?php echo $form->textField($model,'USR_LastName',array('name'=>'last_name','id'=>"last_name",'class'=>'inputtext')); ?></td>

        </tr>
        <tr>
            <td  id="email_label_register" style="text-align:right" class="label"></td>
            <td><?php echo $form->textField($model1,'UEM_Email',array('name'=>'register_email','id'=>"register_email",'class'=>'inputtext')); ?></td>

        </tr>
        <tr>
            <td id="reenter_email_label_register" style="text-align:right" class="label"></td>
            <td><?php echo $form->textField($model1,'repeat_email',array('name'=>'reenter_email','id'=>"reenter_email",'class'=>'inputtext')); ?></td>

        </tr>
        <tr>
            <td id="new_password_label_register" style="text-align:right" class="label"></td>
            <td><?php echo $form->passwordField($model,'USR_Password',array('name'=>'passwd','id'=>"passwd",'class'=>'inputtext')); ?></td>

        </tr>
        <tr>
            <td id="date_of_birth_label_register" style="text-align:right" class="label"></td>

            <td><?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                                                'model'=>$model,                        
                                                'attribute'=>'USR_Date_Of_Birth',
                                                'options'=>array(
                                                    'dateFormat'=>'yy-mm-dd',
                                                    'changeMonth'=>true,
                                                    'changeYear'=>true,
                                                    'showAnim'=>'fold',
                                                    'yearRange'=> '1910:2020',
                                                    'maxDate'=>'new Date();'
                                                ),
                                                'htmlOptions'=>array(
                                                    'id'=>'dob',
                                                    'name'=>'dob',
                                                    'class'=>'inputtext',
                                                    'readonly'=>true,
                                                    'style'=>'width:207px;',
                                                    'language'=>'de'

                                                ),
                                             ));?></td>


        </tr>

        <tr><td class="label"></td><td id="birth_label"></td>
        </tr>
        <tr><td class="label"></td>
        </tr>
        <tr><td class="label"></td><td id="terms_label">
            </td>
        </tr>
    <tr><td>&nbsp;</td></tr>
    <tr><td>&nbsp;<input type="hidden" name="pid" value="<?php echo $pid;?>" /></td>
    <td><?php echo CHtml::Button('Cancel',array('name' => 'cancel_reg_button','id'=>'cancel_reg_button','style'=>'background: #ffffff;color:black')); ?>&nbsp;<?php echo CHtml::submitButton('Sign Up',array('id'=>'button','name' => 'button2','style'=>'background: #6495ED;color:white')); ?></td></tr>
                 </table>
           </div>

我的jQuery表单验证和规则是这样的..

jQuery.validator.addMethod("ageCheck", function(value, element) { 

                var now=new Date();

                var selected_date_array = jQuery("#dob").val().split("-");

                var selected_date = new Date(selected_date_array[0],selected_date_array[1]-1,selected_date_array[2]);

                return selected_date < now;
    }, "Selected date must be less than current date");
 jQuery.validator.addMethod("checkemails", function(value, element) { 

    return value.toLowerCase()==jQuery("#register_email").val().toLowerCase();

}, "Please enter the same value as in the email field");

jQuery(document).ready(function(){

 jQuery('#reenter_email').bind("cut copy paste",function(e) {
      e.preventDefault();
 });

 jQuery('#mlusers-register-form').validate({

        errorClass: "error",
        errorElement: "div",
        rules:{
              reenter_email:{required: true, email: true,checkemails:true},
            passwd:{required: true,minlength:6},
            dob:{required: true,dateISO: true,ageCheck:true},
            first_name:{required:true,firstname: true},
            last_name:{required:true,lastname: true},                   
            register_email:{required: true, email:true,remote:{url:'./index.php?r=user/unique_email_check',async: false}}

        },

        messages:{
                first_name:{required:" First Name field cannot be blank"},
                last_name:{required:" Last Name field cannot be blank"},
                register_email:{required:" Email field cannot be blank",remote:"Email id already registered"},
                reenter_email:{required:" Re-enter Email field cannot be blank"},
                passwd:{required:" New Password field cannot be blank",minlength: "Min length is 6."},
                dob:{required:" Date Of Birth field cannot be blank",dateISO: "Invalid date. Must be formatted yyyy-mm-dd"}

        },
        submitHandler: function(form) {

            jQuery(form).ajaxSubmit({
                url:"./index.php?r=mLUsers/sign_up",
                type:"POST",
                success: function(){
                   jQuery("#success_hide").hide();
                   jQuery(".success").show();
                }
            });
       }
  });
});

对现有电子邮件进行远程验证工作正常,一切正常。

但问题是,在注册表单中,使用 Firebug 将“您的电子邮件”字段的 ID 替换为“重新输入电子邮件”字段的 ID。

远程验证显示错误电子邮件已注册但表单正在提交。这有什么问题?

我的php函数是

public function actionUnique_email_check(){
        //echo "<pre>";print_r($_POST);exit;
        //sleep(10);
        $email=$_GET['register_email'];

        $emails_array=  UserEmails::model()->findAllByAttributes(array('UEM_Email'=>$email));

        if(count($emails_array) > 0){

          echo json_encode(false);

        }
        else{

            echo json_encode(true);
        }

    }

这是一个重大错误。

4

2 回答 2

0

尝试使用类属性而不是 id

于 2013-10-07T06:21:16.597 回答
0

感谢上帝..

最后我找到了解决方案..

实际上在验证器添加方法中我添加了 checkemails 方法......这个函数采用注册电子邮件的值..

如果我将“电子邮件”字段的 ID 更改为“重新输入电子邮件”字段的 ID,则没有 ID 注册电子邮件...然后它返回 true...

我将 checkemails 方法更改为

jQuery.validator.addMethod("checkemails", function(value, element) { 

    return     value.toLowerCase()==jQuery("input[name='register_email']").val().toLowerCase();

  }, "Please enter the same value as in the email field");

然后它工作正常..

谢谢..

于 2013-10-07T08:48:12.087 回答