Quiero que aparezca un cuadro de error, pero ni siquiera se produce el error.

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>

function getUID()
     global $user;
     if ($user->uid) 
          echo $userID;
          header('Location: http://brokendiamond.org/?q=node/40');
function getUN()
     global $user;
     if ($user->uid) 
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 != "")
         return false;

<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'!" />

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

Gracias de antemano, Jonathan

preguntado el 01 de febrero de 12 a las 22:02

Try replacing if (errors != "") { alert(errors); return false; } -

With else {} and see if that works -

I put your code into a local page on my machine (after stubbing the UID and karma points) and I correctly get the alert dialog if karma is less than 500 or I leave the username field blank. Is it possible that you have a blank space in the username field (perhaps your getUN() returns " ")? Otherwise I would check to see if you have other script errors on the page using Firebug in Firefox, or the Developer console in Chrome. -

the problem is mainly when i check for the Karma bit, it doesn't show an error, normaly if the username is correct, but the karma isn't enough, it should show an error but it doesn't -

i do think the problem lays with the javascript, because when i run the php code, and i just do an echo it shows the karma points right, maybe with the var karma = parseInt(<?php echo json_encode(getKarma()); ?>); is there another way to do this? i do think its there. -

0 Respuestas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.