2013-05-01 115 views
-2

我的代码存在多个问题。我已经写了一个带有验证的用户注册表单,但是我需要帮助我写什么来保存在数据库中,以及我是否缺少任何东西。截至目前,这不起作用。当我点击注册时,它只刷新页面。用户注册 - 错误的逻辑

我很感激任何帮助,谢谢。

<!DOCTYPE html> 
<html lang="en"> 
<head> 
<SCRIPT language="JavaScript"> 

       function validateRegistrationForm(){ 
      if(!validateEmailField()) // Invalid email format 
      return false; 
      if(!validatePasswordField()) // Invalid password length 
      return false; 
      if(validateUserNameField()) // invalide characters in email 
     return false; 
} 

      function validateEmailField(){ 
      var x=document.getElementById("email").value; 
      var atpos=x.indexOf("@"); 
      var dotpos=x.lastIndexOf("."); 
      if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) 
{ 
      errorPopup("Not a valid e-mail address"); 
      return false; 
} 
    if(email==x) //If the old email is equal to the current then perform no check for uniqueness. On the server side the email portion will be ignored. 
     return true; 

    return isEmailUnique(); // return true if the email is unique 
} 
</script> 


</head> 

<body class="nobg loginPage"> 

    <header> 
    </header> 
    <div id="content"> 
     <div class="ic"></div> 
     <div class="inner"> 
      <div class="container_12"> 
       <div class="wrapper"> 
        <div class="grid_12"> 
        </div> 
       </div> 
       <div class="wrapper"> 
        <div class="grid_12"> 
         <h2 class="h-pad1">Open an Account with Us</h2> 
         <form action="" id="validate" class="form" method="POST"> 
      <fieldset> 
       <div class="formRow"> 
        <label for="login">Username:</label> 
        <div class="loginInput"><input type="text" name="username" class="validate[required]" id="username" maxlength="15"/></div> 
        <div class="clear"></div> 
       </div> 

       <div class="formRow"> 
        <label for="pass">Password:</label> 
        <div class="loginInput"><input type="password" name="password" class="validate[required]" id="pass" /></div> 
        <div class="clear"></div> 
       </div> 

       <div class="formRow"> 
        <label for="pass">Repeat Password:</label> 
        <div class="loginInput"><input type="password" name="rpassword" class="validate[required]" id="rpass" /></div> 
        <div class="clear"></div> 
       </div> 

       <div class="formRow"> 
        <label for="pass">Email:</label> 
        <div class="loginInput"><input type="text" name="email" class="validate[required]" id="email" /></div> 
        <div class="clear"></div> 
       </div> 

       <div class="formRow5"> 
       <script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=6Lfz39kSAAAAABY7fpEs0x1ZzvcFSP-gClbe8XYb"></script> 
       <noscript> 
       <iframe src="http://www.google.com/recaptcha/api/noscript?k=6Lfz39kSAAAAABY7fpEs0x1ZzvcFSP-gClbe8XYb" height="300" width="500" frameborder="0"></iframe><br/> 
       <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea> 
       <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/> 
       </noscript> </div> 
       <div class="loginControl"> 
        <input type="submit" value="Register" class="dblueB logMeIn" name="registerBtn"/> 
        <div class="clear"></div> 
       </div> 
      </fieldset> 
     </form> 
          </li> 
         </ul> 
        </div> 
       </div> 
      </div>   
     </div> 
    </div> 
    <footer> 
     </div> 
    </footer> 
</body> 
</html> 
+0

在validateEmailField您引用'如果(电子邮件== X )'但是据我所见,电子邮件变量永远不会被定义。 'isEmailUnique()'函数似乎没有被定义。 'errorPopup()'函数似乎没有被定义。你的'validateRegistrationForm()'函数似乎返回false或undefined不管怎么说 - 它永远不会返回true,并且我也看不到任何调用这个函数的东西? 'validateUsernameField()'和'validatePasswordField()'函数似乎没有被定义。您有一个带有提交按钮和POST方法的表单元素,但没有操作URL。 – 2013-05-01 23:02:28

回答

1

据我所知 - 你没有任何东西将表单的提交连接到你写的验证代码。您提交表单时,您的validateRegistrationForm()函数是否被调用?

至于你的功能 - 如果表单元素有效,你会想返回true,如果不是,你会返回false。返回false将取消提交表格。

+0

用新代码修复并更新OP – user2338118 2013-05-01 22:54:11

1

在大多数情况下,您不能使用JavaScript写入数据库,因为JS是客户端代码,数据库往往位于服务器上。在这种情况下,您需要使用服务器端语言来完成此操作(如.NET,PHP,Java等)。如果可以说出要写入的数据库以及正在使用的服务器语言(如果您已使用任何服务器语言),则可能会得到更详细的答案。

+0

我只想要一个简单的用户注册表单,当用户注册时,他们可以登录。 – user2338118 2013-05-01 22:39:48

+1

这意味着你需要一些方法来跟踪他们的细节,这意味着你(几乎肯定)需要一个数据库,这意味着你(几乎肯定)需要一些服务器端代码。我建议最简单的方法(根据我自己的个人喜好)是PHP,但这取决于一些因素,比如您的网站托管位置,您必须在该服务器计算机上安装软件的访问权限(如果有)以及/或者已经安装了哪些软件。 – 2013-05-01 22:55:47

+0

正如克里斯所说,这取决于您的网站托管在哪里,但许多网络主机允许您使用MySQL和PHP。如果您不确定如何使用这两种资源,可以在网上找到使用PHP写入MySQL数据库的大量资源。 – Kurt 2013-05-01 23:02:35

0

您点击注册按钮之前,有一个JavaScript错误...

14号线1列: “未捕获的SyntaxError:意外的标记”

+0

修复了错误,你找到了吗? – user2338118 2013-05-01 22:53:16

+0

不,我不能在发布它之前测试新的固定代码。 – 2013-05-01 23:08:39