php - JavaScript弹出密码检查

标签 php javascript html jquery

我正在尝试为我的网站制作一个注册表格,它要求用户输入一次密码,当他们点击提交时,会弹出一个 JavaScript 框并再次向用户询问,并与旧密码进行核对,如果他们不一样,它会留在加入页面上并告诉他们密码不匹配。我该怎么做呢?

这是我的 HTML 文档:

<h2>New Account Registration.</h2>

            <table width="600" cellpadding="1" style="text-align:center;">
  <form action="join.php" method="get"  >
    <tr>
      <td colspan="1"><font color="#FF0000"></font></td>
    </tr>
    <tr>
      <td>Company Name:</td>
      </tr>
      <tr>
      <td><input style="background-color: #FFF;" name="companys_name" type="text" placeholder="Google" required /></td>
    </tr>
    <tr>
      <td>First Name:</td>
      </tr>
      <tr>
      <td ><input style="background-color: #FFF;" name="admin_first_name" type="text" placeholder="John" required /> 
        </td>
    </tr>
    <tr>
      <td>Last Name: </td>
      </tr>
      <tr>
      <td>
        <input style="background-color: #FFF;" name="admin_last_name" type="text" placeholder="Doe" required />
      </td>
    </tr>

    <tr>
      <td>Phone Number:</td>
      </tr>
      <tr>
      <td><input style="background-color: #FFF;" type="tel" name="admin_phone" pattern="[0-9]{3}-?[0-9]{3}-?[0-9]{4}" required placeholder="123-123-1231"></td>
    </tr>
    <tr>
      <td>Website: </td>
      </tr>
      <tr>
      <td><input style="background-color: #FFF;" type="url" id="orderWebsite" placeholder="http://domain.com"  /></td>
    </tr>

    <tr>
      <td>Email: </td>
      </tr>
      <tr>
      <td><input style="background-color: #FFF;" type="email" id="orderEmail" placeholder="name@domain.com" required /></td>
    </tr>
    <tr>
      <td> Password: </td>
      </tr>
      <tr>
      <td> <input style="background-color: #FFF;" name="admin_password" type="password" required /> 
      </td>
    </tr>   
    <tr>
      <td><input type="submit" name="Submit" value="Register!" onclick="register()" /></td>
    </tr>
  </form>
</table>

这是它连接到的 PHP 页面:

<?php

$errorMsg = "";

// First we check to see if the form has been submitted 

if (isset($_POST['companys_name'])){

    //Connect to the database through our include 

    include_once "connect_to_mysql.php";

    // Filter the posted variables

    $companys_name = preg_replace("[^A-Za-z0-9]", "", $_POST['companys_name']); // filter everything but numbers and letters

    $admin_first_name = preg_replace("[^A-Za-z]", "", $_POST['admin_first_name']); // filter everything but letters

    $admin_phone = preg_replace("[^0-9]", "", $_POST['admin_phone']);// Filters everything except numbers

    $admin_email = preg_replace("[^A-Z a-z0-9]", "", $_POST['admin_email']); // filter everything but spaces, numbers, and letters

    $admin_url = preg_replace("[^A-Z a-z0-9]", "", $_POST['admin_url']); // filter everything but spaces, numbers, and letters

    $admin_last_name = preg_replace("[^A-Z a-z]", "", $_POST['admin_last_name']); // filter everything but spaces, numbers, and letters

    $admin_email = stripslashes($_POST['admin_email']);

    $admin_email = strip_tags($admin_email);

    $admin_email = mysql_real_escape_string($admin_email);

    $admin_password = preg_replace("[^A-Za-z0-9]", "", $_POST['admin_password']); // filter everything but numbers and letters

    // Check to see if the user filled all fields with

    // the "Required"(*) symbol next to them in the join form

    // and print out to them what they have forgotten to put in

    if((!$companys_name) || (!$admin_first_name) || (!$admin_phone) || (!$admin_last_name) || (!$admin_email) || (!$admin_password)){



        $errorMsg = "You did not submit the following required information!<br /><br />";

        if(!$companys_name){

            $errorMsg .= "--- Company Name";

        } else if(!$admin_first_name){ 

           $errorMsg .= "--- Phone Number 10 Digits"; 

        } else if(!$admin_phone){ 

           $errorMsg .= "--- Phone Number 10 Digits"; 

       } else if(!$admin_last_name){ 
           $errorMsg .= "--- Last Name"; 

       } else if(!$admin_email){ 

           $errorMsg .= "--- Email Address"; 

       } else if(!$admin_password){ 

           $errorMsg .= "--- Password"; 

       } 



    } else {

    // Database duplicate Fields Check

    $sql_companys_name_check = mysql_query("SELECT id FROM toc_companys WHERE companys_name='$companys_name' LIMIT 1");

    $sql_admin_email_check = mysql_query("SELECT id FROM toc_companys WHERE admin_email='$admin_email' LIMIT 1");

    $companys_name_check = mysql_num_rows($sql_companys_name_check);

    $admin_email_check = mysql_num_rows($sql_admin_email_check); 

    if ($companys_name_check > 0){ 

        $errorMsg = "<u>ERROR:</u><br />Your company name is already in use inside our system. Please try another.";

    } else if ($admin_email_check > 0){ 

        $errorMsg = "<u>ERROR:</u><br />Your Email address is already in use inside our system. Please try another.";

    } else {

        // Add MD5 Hash to the password variable

       //$hashedPass = md5($password); 

        // Add user info into the database table, claim your fields then values 

        $sql = mysql_query("INSERT INTO  toc_companys (companys_name, admin_first_name, admin_phone, admin_url, admin_last_name, admin_email, admin_password ) 

        VALUES('$companys_name', '$admin_first_name', '$admin_phone','$admin_url','$admin_last_name', '$admin_email','$admin_password', now())") or die (mysql_error());

        // Get the inserted ID here to use in the activation email

        $id = mysql_insert_id();

        // Create directory(folder) to hold each user files(pics, MP3s, etc.) 

        mkdir("memberFiles/$id", 0755); 

        // Start assembly of Email Member the activation link

        $to = "$admin_email";

        // Change this to your site admin email

        $from = "admin@5mutny.com";

        $subject = "Activate your account!";

        //Begin HTML Email Message where you need to change the activation URL inside

        $message = '<html>

        <body bgcolor="#FFFFFF">

        Hi ' . $admin_first_name . ' at ' . $companys_name . ',

        <br /><br />

        You must complete this step to activate your account with us.

        <br /><br />

        Please click here to activate now &gt;&gt;

        <a href="http://www.testsite.com/activation.php?id=' . $id . '">

        ACTIVATE NOW</a>

        <br /><br />

        Your Login Data is as follows: 

        <br /><br />

        E-mail Address: ' . $admin_email . ' <br />

        Password: ' . $admin_password . ' 

        <br /><br /> 

        Thanks! 

        </body>

        </html>';

        // end of message

        $headers = "From: $from\r\n";

        $headers .= "Content-type: text/html\r\n";

        $to = "$to";

        // Finally send the activation email to the member

        mail($to, $subject, $message, $headers);

        // Then print a message to the browser for the joiner 

        print "<br /><br /><br /><h4>OK $firstname, one last step to verify your email identity:</h4><br />

        We just sent an Activation link to: $admin_email<br /><br />

        <strong><font color=\"#990000\">Please check your email inbox in a moment</font></strong> to click on the Activation <br />

        Link inside the message. After email activation you can log in.";

        exit(); // Exit so the form and page does not display, just this success message

    } // Close else after database duplicate field value checks

  } // Close else after missing vars check

} //Close if $_POST

?>

我的老师希望我做到这一点,当有人点击注册时,会弹出一个 JavaScript 框,要求用户重新输入密码,这样它就会与输入框进行检查,如果它们相同,就会创建他们的帐户如果不是,它不会离开页面,但会告诉他们他们的密码不一样。

最佳答案

通过 JQuery 的伪代码:

$('#submit').click(function(){
  $('#box').show();
});

$('#box > #confirm').click(function(){
  var firstInput = $('#firstInput').val();
  var secondInput = $('#secondInput').val();
  if(!firstInput.equal(secondInput)) {
    //do something if they are not the same
  }
});

关于php - JavaScript弹出密码检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12926351/

相关文章:

php - Magento - 无效的 block 类型

php - 在 Rails 应用程序中启用 PHP 文件夹?

php - 用表达式中的一项替换花括号表达式

html - CSS - 让文本使用兄弟 block 元素的最大宽度

javascript - 访问线和弦图 D3

php - HTML 呈现与 TCPDF(PHP)

javascript - vue.js 缓存视频并播放

javascript - 使用 CSS3 过渡时等效于 jQuery.animate 步进函数

javascript - 如何将标签添加到Asp.net文本框?

html - CSS 添加下拉菜单