<?php /* Template Name: Dummy Practice Page*/?>
<div id="main-content" class="main-content">
<div class="main-content-inner">
<form method="post">
<p><div>
<input name="nametxt" id="nametxt" type="text" style="height:30px; width: 350px; " maxlength="5" placeholder="Name" required><br>
</p></div>
<p><div>
<input name="designationtxt" id="designationtxt" type="text" style="height:30px; width: 350px; " maxlength="50" placeholder="Designation" required><br>
</p></div>
<p><div>
<input name="designationtxt" id="descriptiontxt" type="text" style="height:30px; width: 350px; " maxlength="1000" placeholder="Description" required><br>
</p></div>
<input id="submitbtn" type=\'submit\' style="height:40px; width: 130px; padding:10px; color:dodgerblue; background-color:black; border-radius:20px; " name=\'Submit\' value=\'Add Member\' /><br><br>
</form>
</div>
</div>
<?php
global $wpdb;
$table = $wpdb->prefix.\'tboxteam\';
$data = array(\'name\' => isset($_POST[\'nametxt\']), \'designation\' => isset($_POST[\'designationtxt\']), \'description\' => isset($_POST[\'descriptiontxt\']));
$format = array(\'%s\',\'%s\',\'%s\');
$wpdb->insert($table,$data,$format);
?>
最合适的回答,由SO网友:Wordpress Dev 整理而成
<?php /* Template Name: Dummy Practice Page*/?>
<div id="main-content" class="main-content">
<div class="main-content-inner">
<form method="post">
<p><div>
<input name="nametxt" id="nametxt" type="text" style="height:30px; width: 350px; " maxlength="5" placeholder="Name" required><br>
</p></div>
<p><div>
<input name="designationtxt" id="designationtxt" type="text" style="height:30px; width: 350px; " maxlength="50" placeholder="Designation" required><br>
</p></div>
<p><div>
<input name="descriptiontxt" id="descriptiontxt" type="text" style="height:30px; width: 350px; " maxlength="1000" placeholder="Description" required><br>
</p></div>
<input id="submitbtn" type=\'submit\' style="height:40px; width: 130px; padding:10px; color:dodgerblue; background-color:black; border-radius:20px; " name=\'Submit\' value=\'Add Member\' /><br><br>
</form>
</div>
</div>
<?php
// Checking if form submitted
if(isset($_POST[\'Submit\'])){
// Fetching values if they are not empty.
if( isset($_POST[\'nametxt\']) || isset($_POST[\'designationtxt\']) ||isset($_POST[\'descriptiontxt\']) ){
global $wpdb;
$data = array(\'name\' => $_POST[\'nametxt\'], \'designation\' => $_POST[\'designationtxt\'], \'description\' => $_POST[\'descriptiontxt\'] );
$table = $wpdb->prefix.\'tboxteam\';
$format = array(\'%s\',\'%s\',\'%s\');
$wpdb->insert($table,$data,$format);
}
}
?>