好的,这里是你应该如何以这种正确的方式。。。
在模板文件中,您可以填写表单:
<form id="myForm" name="myform" action="<?php echo esc_attr( admin_url(\'admin-post.php\') ); ?>" method="POST">
<input type="hidden" name="action" value="save_my_custom_form" />
<select id="brandSel" size="1">
<option selected="selected" value="">-- Select Brand --</option>
<option>Abba</option>
<option>AG Hair</option>
</select>
<input type="submit" value="submit" />
</form>
和在函数中。必须添加的php文件(或插件中的文件)
admin_post_{action}
:
function my_save_custom_form() {
global $wpdb;
$inputValue = $_POST[\'newValue\'];
$wpdb->insert(
\'catalog\',
array( \'brandSel\' => $inputValue ),
array( \'%s\' ),
);
wp_redirect( site_url(\'/\') ); // <-- here goes address of site that user should be redirected after submitting that form
die;
}
add_action( \'admin_post_nopriv_save_my_custom_form\', \'my_save_custom_form\' );
add_action( \'admin_post_save_my_custom_form\', \'my_save_custom_form\' );