我想要弹出一个错误框,但它甚至不会发生错误

时间:2012-02-01 22:51:37

标签: php javascript html forms

我已经制作了一个webform,我有一个脚本用于处理这个表单(php)这个脚本工作正常,但我也做了一个javascript错误检查器,现在当我尝试在该脚本中获取一些php时,它不知何故,错误,并没有检查我的错误,在JavaScript,

下面你会发现我为错误handeling写的代码,我还没有完成,但我现在卡住了,因为我需要去我的数据库检查一些东西,并且javascript错误处理程序错误。

快速漫步: 为了测试这个错误处理,我自己有0业力。 我点击提交,即使我没有填写我的用户名, 它没有显示错误。并直接将我带到php处理程序,它确实发现错误。

Do you like the content on our website? Do you want to be a part of it? Want to earn more Karma?<br />
Do you have what it takes to be a content creator? Then sign up here!<br> <br>

<?php 
function getUID()
{
     global $user;
     if ($user->uid) 
     { 
          $userID=$user->uid;
          echo $userID;
     }
     else
    {
          header('Location: http://brokendiamond.org/?q=node/40');
    }
}
function getUN()
{
     global $user;
     if ($user->uid) 
     { 
          $username=$user->name;
     }
echo $username;
}

function getKarma()
{
     include "php-scripts/DBConnection.php";
     $con = getconnection();
     mysql_select_db("brokendi_BD", $con);
     $result = mysql_query("SELECT * FROM userpoints WHERE uid='getUID()'");
     $row = mysql_fetch_array($result);
     $currentkarma = (int)$row['points'];

     echo $currentkarma;
}
?>

<script type="text/javascript">
function validateForm()
{
var name=document.forms["CCF"]["username"].value;
var karma = parseInt(<?php echo json_encode(getKarma()); ?>);
var errors = "";

     if (name==null || name=="")
     {
         errors += "Error: The username field cannot be empty";
     }

    if (karma < 500)
    {
         errors += "Error: Not enough Karma, you need at least 500 karma to submit this form";
    }

    if (errors != "")
    {
         alert(errors);
         return false;
    }
}
</script>

<form name="CCF" action="php-scripts/sendmail.php" method="post" onsubmit="return validateForm()" >
Username: &nbsp;&nbsp;&nbsp;&nbsp
<input type="hidden" name="UserID" value="<?php getUID() ?>">
<input type="text" name="username" value="<?php getUN() ?>" /><br>
E-mail adress: 
<input type="text" name="mail" /><br><br>
What type of 'Content Creator' do you want to become? <br />
<input type="radio" name="CCT" value="Blogger" /> Blogger<br />
<input type="radio" name="CCT" value="Livestreamer" /> Livestreamer<br> <br>
What's your motivation?<br />
<textarea name="motivation" cols="60" rows="6"></textarea><br><br>
Why should we pick you as content creator?<br />
<textarea name="whyshouldwe" cols="60" rows="6"></textarea><br><br>
Do you have some reference material?<br />
<textarea name="reference" cols="60" rows="6"></textarea><br><br>
<h3>Rules to content creation</h3>
<p>You can only submit this once every day, the other versions will not be read, and you will lose Karma for each submit.<br />
When u submit this form, we will examine your account, and we will take a close look to your reference material.<br>
<h4>For Livestreamers Only</h4>
If we think you have what it takes to be a livestreamer ( frequent hours required ) we will examine your stream, and your computer/internet potential.<br />
If that is good enough for the website, you'll become a content creator.<br>
<h4>For Bloggers</h4>
If we think you are blogging material for out website, you will become a content creator, once you are accepted onto the team we will track your progress.<br />
If however you neglect your power or publish inappropriate content, then we will have no choice but to remove you from our team and will revert you to a regular user account.<br><br>
<input name="Send" type="submit" id="art-button-wrapper" value="I donate 500 Karma, and want to become a 'Content Creator'!" />
</form>

我看不出问题是什么,或者为什么它不起作用,因为我在javascript中还不够熟练。

提前致谢, 乔纳森

0 个答案:

没有答案