doujie7886 2010-07-29 19:48
浏览 53
已采纳

Javascript密码更改表单验证不适用于IE8

got this function to validate two fields from a changing password form and it's doesn't seem to work at IE8. FF, Opera, Safari and Chrome work.

function chk_form_pw()
{
 if(document.getElementById('new_passwd').value == '')
 {
  alert("<?php _e('Please enter New Password') ?>");
  document.getElementById('new_passwd').focus();
  return false;
 }
 if(document.getElementById('new_passwd').value.length < 5 )
 {
  alert("<?php _e('Please enter New Password minimum 5 chars') ?>");
  document.getElementById('new_passwd').focus();
  return false;
 }
 if(document.getElementById('cnew_passwd').value == '')
 {
  alert("<?php _e('Please enter Confirm New Password') ?>");
  document.getElementById('cnew_passwd').focus();
  return false;
 }
 if(document.getElementById('cnew_passwd').value.length < 5 )
 {
  alert("<?php _e('Please enter Confirm New Password minimum 5 chars') ?>");
  document.getElementById('cnew_passwd').focus();
  return false;
 }
 if(document.getElementById('new_passwd').value != document.getElementById('cnew_passwd').value)
 {
  alert("<?php _e('New Password and Confirm New Password should be same') ?>");
  document.getElementById('cnew_passwd').focus();
  return false;
 }
}

This is the form:

<form name="registerform" id="registerform" action="<?php echo get_option( 'siteurl' ).'/?page=account&chagepw=1'; ?>" method="post">
<p><label><?php _e('New Password'); ?> <span class="indicates">*</span></label></p>
<p><input type="password" name="new_passwd" id="new_passwd"  class="lostpass_textfield" /></p>
<p><label><?php _e('Confirm New Password'); ?> <span class="indicates">*</span></label></p>
<p><input type="password" name="cnew_passwd" id="cnew_passwd"  class="lostpass_textfield" /></p>
<p><input type="submit" name="Update" onclick="return chk_form_pw();" value="<?php _e('Update Password') ?>" class="btn grey"/></p>
</form>

And here is the chagepw=1 thing:

<?php
if($_POST)
{
    if($_REQUEST['chagepw'])
    {
        $new_passwd = $_POST['new_passwd'];
        if($new_passwd)
        {
            $user_id = $current_user->data->ID;
            wp_set_password($new_passwd, $user_id);
            $message1 = "Password Changed successfully.You need to sign back in.";
        }

    }else
    {
        $user_id = $userInfo['ID'];
        $user_add1 = $_POST['user_add1'];
        $user_add2 = $_POST['user_add2'];
        $user_city = $_POST['user_city'];
        $user_state = $_POST['user_state'];
        $user_country = $_POST['user_country'];
        $user_postalcode = $_POST['user_postalcode'];

        $buser_add1 = $_POST['buser_add1'];
        $buser_add2 = $_POST['buser_add2'];
        $buser_city = $_POST['buser_city'];
        $buser_state = $_POST['buser_state'];
        $buser_country = $_POST['buser_country'];
        $buser_postalcode = $_POST['buser_postalcode'];
        $user_address_info = array(
                            "user_add1"     => $user_add1,
                            "user_add2"     => $user_add2,
                            "user_city"     => $user_city,
                            "user_state"    => $user_state,
                            "user_country"  => $user_country,
                            "user_postalcode"=> $user_postalcode,
                            "buser_name"    => $_POST['buser_fname'].'  '.$_POST['buser_lname'],
                            "buser_add1"    => $buser_add1,
                            "buser_add2"    => $buser_add2,
                            "buser_city"    => $buser_city,
                            "buser_state"   => $buser_state,
                            "buser_country" => $buser_country,
                            "buser_postalcode"=> $buser_postalcode,
                            );
        update_usermeta($user_id, 'user_address_info', serialize($user_address_info)); // User Address Information Here
        $userName = $_POST['user_fname'].'  '.$_POST['user_lname'];
        $updateUsersql = "update $wpdb->users set user_nicename=\"$userName\", display_name=\"$userName\"  where ID=\"$user_id\"";
        $wpdb->query($updateUsersql);
        $message = "Information Updated successfully.";
    }
}
$userInfo = $General->getLoginUserInfo();
$user_address_info = unserialize(get_user_option('user_address_info', $user_id));
$user_add1 = $user_address_info['user_add1'];
$user_add2 = $user_address_info['user_add2'];
$user_city = $user_address_info['user_city'];
$user_state = $user_address_info['user_state'];
$user_country = $user_address_info['user_country'];
$user_postalcode = $user_address_info['user_postalcode'];
$display_name = $userInfo['display_name'];
$display_name_arr = explode(' ',$display_name);
$user_fname = $display_name_arr[0];
$user_lname = $display_name_arr[2];
$buser_add1 = $user_address_info['buser_add1'];
$buser_add2 = $user_address_info['buser_add2'];
$buser_city = $user_address_info['buser_city'];
$buser_state = $user_address_info['buser_state'];
$buser_country = $user_address_info['buser_country'];
$buser_postalcode = $user_address_info['buser_postalcode'];
$bdisplay_name = $user_address_info['buser_name'];
$display_name_arr = explode(' ',$bdisplay_name);
$buser_fname = $display_name_arr[0];
$buser_lname = $display_name_arr[2];

if($_SESSION['redirect_page'] == '')
{
    $_SESSION['redirect_page'] = $_SERVER['HTTP_REFERER'];
}
if(strstr($_SESSION['redirect_page'],'page=checkout'))
{
    $login_redirect_link = get_option( 'siteurl' ).'/?page=checkout';
}
?>  
  • 写回答

2条回答 默认 最新

  • douju6542 2010-07-30 13:11
    关注

    Finally got it done using the JQuery script posted before:

    http://code.google.com/p/form-validation-engine/downloads/list

    It's been really easy to fit into my previous code and works flawlessly through every browser tested.

    Thank you all for your help!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器