I'm absolutely no javascript guru so this might be very very simple question.
How do i replace a form with a "thank you!". What I mean is, after you press submit i want the form to be replaced with either "Thank you!" or "An error has occurred!"?
In advance thank you for the help :D
EDIT:
Here is the processing. It's located before the
if(isset($_POST['sendmail'])) {
//Data from the form
$name = trim(strip_tags($_POST['name']));
$email = trim(strip_tags($_POST['email']));
$message = trim(strip_tags($_POST['message']));
//Data set by the script
$subject = 'Mail fra ';
$subject .= $name;
$subject .= ' via lindegaardsign.dk';
$to = 'nf.denmark@gmail.com';
if(validate_email($email) && !empty($email) && !empty($message)) {
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
//Send mail
if(mail($to , $subject , $message , $headers)) {
$message = '<div class="contactresponse">Tak for din henvendelse. Vi besvarer den hurtigst muligt.</div>';
} else {
$message = '<div class="contactresponse">Der skete fejl ved afsendelsen af din henvendelse.</div>';
}
} else {
$message = '<div class="contactresponse">Husk at udfylde email, meddelelse.</div>';
}
}
and this is the form it self.
<article class="con460">
<header><h2>Hurtig kontakt</h2></header>
<section id="quick_contact_form">
<p>
N开发者_StackOverflowedenfor ser du hvor, og hvornår vi udstiller vores nisser og dekorationer. Kig forbi og mød os til en snak om de hjemmelavede produkter.
</p>
<?php if(isset($message)) :?>
<?php echo $message; ?>
<?php else: ?>
<form class="contact" id="contact_form" action="start.php" method="post">
<label>Navn:</label>
<input type="text" name="name" value="">
<label>Email:</label>
<input type="text" name="email" value="">
<label>Besked:</label>
<textarea name="message"></textarea>
<input type="reset" name="reset" value="Annuller">
<input type="submit" name="sendmail" id="sendmail" value="Send">
</form>
<?php endif; ?>
</section>
</article>
I hope this helps a little.
You can't do this using JavaScript. You'll have to process the sent form on the server side and send an appropriate message back to the client.
One possibility is to enhance your form with an XMLHttpRequest
sending the form's content to the server and let the callback function replace the form with a (success or failure) message. That said, I'd highly recommend to use the former process anyway and only extend it with this kind of processing once the former works correctly (and using XMLHttpRequest
s is not something for beginners). That way you'll ensure your form still works if JavaScript is unavailable.
精彩评论