I am still studying php and java script. I am creating a simple contact form and set the form action to the same page using $_Server[php_self]
What I want to do is when someone submit to my form, it will show a message including the name that was submitted on the same page. replace the contact form with the message.
I also tried pointing action to a different php page. and it still did not work. Does Javascript work like that? or I have to use different code or language to do that.
Here is my code
<!DOCTYPE html>
<html>
<head>
<?php
include 'action.php';
?>
<title> My profle</title>
<meta name="robots" content="noindex">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="contact">
<form class="form" class="contact" id="contact-form" action="action.php" method="POST">
Name: <br>
<input type="text" class="field" name="name"><br>
Number:<br>
<input type="text" class="field" name="number"><br>
Email:<br>
<input type="email" class="field" name="email:>"<br>
<br>
<input type="submit" class="submit" name="submit" value="submit"
onclick ="document.getElementById('contact-form').innerHTML='<?php thankyou();?>'">
</form>
</div>
</body>
</html>
Then here is the action.php
<?php
function thankyou(){
$name = $_POST['name'];
echo "Thank you"." $name ! Your message has been submitted.";
}
?>