I am working on my first Website! Its a Single Page Design with a simple contact form (two input fields, a textarea and a checkbox and submit button) at the end of the page! The page is ready... the only thing that´s missing is the PHP for the contact form. When the contact form is submitted I would like to show a message (message delivered) on the same page! My Question: For this purpose do I need to convert the whole index.html to index.php ?? It seems to be the only way for the action attribute of the form to stay on the same page! Or is it better to add also Ajax for this purpose? All tutorials use the index.php...
Please help!
I would say yes, make it a .php file. A PHP file can have plain HTML in it. Your index.php could look something like this:
<?php
if ( isset( $_POST['submitted'] ) ) {
$message = 'Your email has been sent!';
// Process your form and send email here
}
?>
<html>
<head>
...
</head>
<body>
<?php
if ( $message ) {
echo "<div class='message'>$message</div>";
}
?>
<!--The rest of your body...-->
</body>
</html>
when you write one line in PHP language in your page you must convert to page.html to page.php
to show a message try to use this
echo "<script> alert('message delivered '); window.location.href='index.php';</script>" ;