I have a site hosted by a hosting company. I am using their form processing feature to process a contact form by inserting the following code into form’s HTML.
I am wondering if that’s possible ,using Javascript, to display a “Thank you. Your message has been sent” kind of message in the message field of the form, after user hits submit button.
So, why not redirect to a thank you message?
Alternatively, use JS to display a “Message successfully submitted” kind of message on the redirect page, then have it vanish after a few seconds.
I could help you with that if that seems like a good option.
I would also have thought that your hosting company would have an option for such an eventuality.
Who are they? Do you have links to any kind of documentation?
Thanks for the quick response. I am not familiar with JS so would appreciate your help. If you can provide me with step-by-step instructions that would be great!
The company is http://www.bluehost.com/ I am not sure they have documentation on this because they told me I would need to customize such message myself.
Please, see attached doc file with some instructions on using the feature that I am using to process the form.
Thanks for the tip, Pullo. I created a separate page and it gets redirected to that page with the message. The only thing is that a blue “redirect” link in the top left corner of the browser flashes for 1 second and then disappears after I hit submit button. Is it supposed to work that way with redirect feature or it just depends on the speed of my internet connection?
I just spoke with my host support and they said that ‘redirect’ link flashes too fast and they are not able to actually catch what it says…:), however, they said it’s part of their ‘redirect’ feature that I use so it can’t be fixed on their end as this is the way it works for now.
You’ll see, that this is nothing more than a simple form, which gets submitted to a file called “submit.php”
submit.php will then check the data it received. If validation fails, it’ll show an error message, otherwise it’ll show a success message.
In our example, I’ll make all of the fields mandatory and I’ll validate the email address against a regular expression:
<?php
$name = filter_var($_POST['name'],FILTER_SANITIZE_STRING);
$subject = filter_var($_POST['subject'],FILTER_SANITIZE_STRING);
$email = filter_var($_POST['email'],FILTER_SANITIZE_STRING, FILTER_VALIDATE_EMAIL);
$message = filter_var($_POST['message'],FILTER_SANITIZE_STRING);
$error = "";
if (empty($name)){
$error .= "You didn't enter a name <br />";
}
if (empty($subject)){
$error .= "You didn't enter a subject <br />";
}
if (empty($email)){
$error .= "You didn't enter an email address <br />";
} elseif (!eregi("^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,})\\.?$", $email)){
$error .= "The email address appears to be invalid <br />";
}
if (empty($message)){
$error .= "You didn't enter a message <br />";
}
if (empty($error)) {
echo "All fields filled out correctly!";
} else {
echo $error;
}
?>
Copy this code to your PC, name the files accordingly then upload them to your server.
Then let me know if this all works or if you have any questions.
After that we’ll move on to the next step - sending the message.
“Your message has been sent” appears in a blank browser window after I hit submit. I wanted it appear within text area of the form - same way when I use my host ‘redirect’ feature.
After I hit ‘submit’ it takes a long time to process.
I am not receiving a test message that I sent to my host webmail.
Please, take a look at form HTML and submit.php code below:
Building a contact form, although not overly complicated, does involve a number of steps and moving parts (so to speak). It is my intention to get the form working first of all, then customize it in a second step. Don’t worry
This sounds like your provider has blocked PHP’s mail function.
The reason might be that the mail function is sometimes seen as a security risk, as a badly coded contact form can be used as a spam relay.
The code you posted looks fine.
Would it be possible for you to contact your hosting company and ask if they allow you to build your own contact forms and more specifically if PHP’s mail function is specifically blocked on their servers?