At first i included the JS in an external script, but that didn't work.
But even with the script inside the same page it won't work.
Problem is that when the submit-button is pressed, a JS check-function should stop the php from sending the mail (or give a error-page), but it doesn't.
I included a "return", but i don't know if a JS-return gives the same result as a PHP-return and if both understands each others return.
I included JS to show messages if a field is empty or faulty after submitting, so i tried removing the "method" from the form-tag.
Just to check how and if my JS was working.
What happens next is...nothing!
Tried showing (.show) the error-messages on submitting (as a test) and that works...for a split second.
Then the page refreshes/reloads and the error-message disapears again.
Please help!
This is what i got sofar:
Code: Select all
<form action="mailformulier.php" method="post">
<table cellspacing="10" class="contact">
<tr><td>Naam:</td><td><input name="klant_naam" class="inputfield" id="name" value="<?php echo $_SESSION['naam']; ?>"></td><td><span id="nameSyntax">Er is iets mis met Uw naam.</span><span id="nameEmpty">U heeft geen naam ingevoerd.</span></td></tr>
<tr><td>Email:</td><td><input name="klant_mail" class="inputfield" id="mail" value="<?php echo $_SESSION['mail']; ?>"></td><td><span id="mailSyntax">Er is iets mis met Uw mailadres.</span><span id="mailEmpty">U heeft geen mailadres ingevoerd.</span></td></tr>
<tr><td>Onderwerp:</td><td><SELECT NAME="klant_subject">
<OPTION <?php echo $_SESSION['select1']; ?> >Copyright-vraag</OPTION>
<OPTION <?php echo $_SESSION['select2']; ?> >Bestelling plaatsen</OPTION>
<OPTION <?php echo $_SESSION['select3']; ?> >Vraag over een foto</OPTION>
<OPTION <?php echo $_SESSION['select4']; ?> >Vraag over een verhaal</OPTION>
<OPTION <?php echo $_SESSION['select5']; ?> >Suggesties</OPTION>
<OPTION <?php echo $_SESSION['select6']; ?> >Algemeen</OPTION>
</SELECT></td></tr>
<tr><td valign="top">Bericht:</td><td><textarea name="klant_bericht" cols="50" rows="10"><?php echo $_SESSION['bericht']; ?></textarea></td><td><span id="messageEmpty">U heeft geen bericht ingevoerd.</span></td></tr>
<tr>
<td></td>
<td>
<input type="submit" value="Verstuur mijn bericht!" onSubmit="return formCheck();">
</td>
</tr>
</table>
</form>Code: Select all
function formCheck (){
//set vars
var checkNameSyntax = "/[a-z0-9_&-]+/i";
var checkMailSyntax = "/^[a-z0-9\'\\.\^+_-]+@[a-z0-9-]+\\.+[a-z0-9]{2,6}$/i";
//check for errors
//check name
if (klant_naam.test(checkNameSyntax) == false){
if (klant_naam.test("") == true){
jQuery('#nameEmpty').show();
}
else {
return false;
jQuery('#nameSyntax').show();
};
}
//check mail
else if (klant_mail.test(checkMailSyntax) == false){
if (klant_mail.test("") == true){
jQuery('#mailEmpty').show();
}
else {
return false;
jQuery('#mailSyntax').show();
};
}
//check message
else if (klant_bericht.test("") == true){
return false;
jQuery('#messageEmpty').show();
}
else {
return true;
}
}