首先在数据库中创建所需表单字段的表,然后将代码放入新创建的custom template.
<?php
if (!empty($_POST)) {
global $wpdb;
$table = table_name;
$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 } ?>