这是在页面中添加表单的简单代码:
add_shortcode( \'myform\', \'add_myform\' );
function add_myform( $atts ) {
if ( isset( $_POST[\'myname\'] ) ) {
$myname = $_POST[\'myname\'];
update_option( \'myname\', $myname );
} else {
$myname = get_option( \'myname\' );
}
$myform = "<form method=\'post\' action=\'\'>";
$myform .= "<input type=\'text\' name=\'myname\' value=\'" . $myname . "\'>";
$myform .= "<input type=\'submit\' value=\'Submit\'>";
$myform .= "</form>";
return $myform;
}
添加短代码
[myform]
在页面中,将显示表单。