Reputation: 343
I have the tiny homepage, which works in the same window by hiding/showing necessary blocks via display block/none properties using JQuery script which is:
$(document).ready(function(){
$(".show").click(function (){
$(".web, .about, .tel, .email").hide();
$("." + $(this).attr("show-class")).fadeIn("fast");
});
});
HTML is:
<li><a href="#" class="show" show-class="email">E-mail</a></li>
<div class="email">
<form method="post" action="">
<input name="name" placeholder="Name (required)">
<input name="email" type="email" placeholder="E-mail (required)">
<textarea name="message" placeholder="Message"></textarea>
<input name="submit" type="submit" value="Submit">
</form>
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = '[email protected]';
$subject = 'Hi! From Example.com';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit']) {
if ($name != '' && $email != '') {
if (mail ($to, $subject, $body)) {
echo '<p>Your message has been sent.</p>';
} else {
echo '<p>Something went wrong, go back and try again.</p>';
}
} else {
echo '<p>Please fill in required information.</p>';
}
}
?>
</div>
And the problem is after successfully or not, submitting the form (pressing the submit button) the block with form hides and only after pressing "E-mail" link again one of the messages (like "Your message has been sent.") appears below/along with the form.
So how could I stop the form from disappearing after submitting it?
Thank you!
Upvotes: 0
Views: 39
Reputation: 1407
Remove $(".web, .about, .tel, .email").hide();
That's what's hiding your inputs.
Adjustment to your code
$(document).ready(function() {
$(".show").click(function() {
$("." + $(this).attr("show-class")).fadeIn("fast");
});
});`
Upvotes: 1