getting post data in a plugin
hey guys when i am writing my plugin how do i get the POST data from the textbox and insert it into the db.
I tried but i am only able to create a table.
T开发者_C百科hanks
Assume you have a form like the one below
<form name="form1" method="post" action="">
<p>First Name:
<input type="text" name="first_name" size="20">
</p>
<p>Last Name:
<input type="text" name="last_name" size="20">
</p>
<p class="submit">
<input type="submit" name="Submit" class="button-primary" value="Create" />
</p>
</form>
Then to get the posted data you would write something like the one below.
<?php
if( isset($_POST['Submit']) && $_POST['Submit'] == 'Create' ) {
//Reads the posted values
$first_name = $_POST[ "first_name" ];
$last_name = $_POST[ "last_name" ];
global $wpdb;
$table_name = $wpdb->prefix . "names";
$rows_affected = $wpdb->insert( $table_name, array( 'f_name' => $first_name, 'l_name' => $last_name) );
}
?>
Depending on the information your plugin needs, the structure of the form and inserting it into the database will vary.
精彩评论