In javascript i want to know how to send data to php file using post method. I have tried diffewrent method. But i didn't get any output so please help me. My code is shown below.
index.php
<form method="post" name="form" enctype="multipart/form-data">
<input type="text" name="name" id="name" placeholder="Name" required/>
<input type="email" name="email" id="email" placeholder="Email" required/>
<input type="password" name="pass" id="pass" placeholder="Password" required/>
<input type="submit" name="submit" value="Send" onclick="myFunction()"/>
</form>
<script>
function myFunction() {
var name = document.getElementById("name").value;
var email = document.getElementById("email").value;
var password = document.getElementById("password").value;
//// I want post the values to profile.php
}
</script>
profile.php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
}
onClickfunction attached to submit returntrue, or remove it completely. In your case its better to remove the onclick event and the JS codes, it should automatically allow the POST to your PHP page.