When i click on submit it doesn't create new posts in the posttype. It just refreshes the page.The below is a pagetemplate assigned to page.
<?php
if(isset($_POST['submit'])){
global $wpdb;
$wpdb->insert( 'contacts', array('post_title'=>$_POST['name'],'email'=>$_POST['email']));
}
?>
<form method="post" action="">
<input type="name" id="inputName" placeholder="Name">
<input type="email" id="inputEmail" placeholder="Email">
<button type="submit">SUBMIT</button>
</form>
You need to add name attribute
in your form element
<input type="name" id="inputName" name="name" placeholder="Name">
<input type="email" id="inputEmail" name="email" placeholder="Email">
<button type="submit" name ="submit">SUBMIT</button>
You just need to change the HTML
<form method="post" action="">
<input type="text" id="inputName" placeholder="Name" name="name">
<input type="text" id="inputEmail" placeholder="Email" name="email">
<button type="submit" name="submit">SUBMIT</button>
</form>
<form method="post" action="">
<input type="text" id="inputName" placeholder="Name" name="username">
<input type="text" id="inputEmail" placeholder="Email" name="useremail">
<input type="submit" name="submit" value="submit">
</form>
<?php if(isset($_POST['submit'])){
global $wpdb;
$wpdb->insert( 'contacts', array('post_title'=>$_POST['username'],'email'=>$_POST['useremail']));} ?>
Now Check. I think it's working properly.