dth20986 2012-02-01 22:51
浏览 24

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

i have made a webform, and i have a script for the handeling of this form (php) this script works fine, but i also made a javascript error checker, now when i try to get some php in that script, it somehow bugs, and doesn't check my errors, in javascript,

below you will find the code i wrote for the error handeling, i'm not finished yet, but i'm currently stuck, since i need to go to my database to check something, and the javascript error handler bugs there.

quick walktrough: I myself have 0 karma for the purposes of testing this error handling. i click submit, and even tho i haven't filled in my username, it doesn't show an error. and brings me directly to the php handler wich does find errors.

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>

I can't see what the problem is, or why it won't work because i'm not skilled enough yet in javascript.

Thanks in advance, Jonathan

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 Unity接入微信SDK 无法开启摄像头
    • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
    • ¥20 cad图纸,chx-3六轴码垛机器人
    • ¥15 移动摄像头专网需要解vlan
    • ¥20 access多表提取相同字段数据并合并
    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算
    • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
    • ¥20 有人知道这种图怎么画吗?
    • ¥15 pyqt6如何引用qrc文件加载里面的的资源