I have never used WordPress before, but have a lot of programming experience. My question is, how to create customs forms in WordPress?
I need to create a form where a user fills some input fields and on submit the data should be stored in the database. I don’t need any notification on saving.
I also need to query the data and get the output in an HTML table.
Thanks
I got the problem solution myself. See the code below this will do that.
Put the code inside your newly created custom template.
<?php
if (!empty($_POST)) {
global $wpdb;
$table = wp_achord;
$data = array(
'name' => $_POST['yourname'],
'chord' => $_POST['chord']
);
$format = array(
'%s',
'%s'
);
$success=$wpdb->insert( $table, $data, $format );
if($success){
echo 'data has been save' ;
}
} else {
?>
<form method="post">
<input type="text" name="yourname">
<textarea name="chord"></textarea>
<input type="submit">
</form>
<?php
}
?>