php - WordPress Custom Form submit data view on admin panel? -
i created custom form on site 2 fields , submit button.
take @ form:
<div class="control-group"> <label class="control-label" for="name">name</label> <div class="controls"> <input type="text" name="name" placeholder="your name" class="form-control"> </div> </div> <div class="control-group"> <label class="control-label" for="number">mobile</label> <div class="controls"> <input type="number" name="number" placeholder="017xxxxxxxx" class="form-control"> </div> </div> <button type="submit" value="sub" name="sub" class="btn btn-success btn-block btn-sm martop15">submit!</button>
when site visitor submit form, want display submitted data onto wordpress admin panel, can delete them individually.
so how can without plugin?
you need use "wp_list_table" class
<?php if(!class_exists('wp_list_table')) { require_once( abspath . 'wp-admin/includes/class-wp-list-table.php' ); } class tt_orders_list_table extends wp_list_table { function __construct() { parent::__construct( array( 'singular' => 'id', 'plural' => 'id', 'ajax' => false )); } function column_default($item, $column_name) { switch($column_name) { case 'user_firstname': case 'user_login': case 'user_email': case 'paid_charge': case 'additional_member': case 'date': return $item->$column_name; default: return print_r($item,true); //show whole array troubleshooting purposes } } function column_user_firstname($item) { $actions = array( 'delete' => sprintf('<a href="users.php?page=%s&action=delete&id=%s&wp_http_referer=%s">delete</a>', $_request['page'], $item->id, 'wp-admin/users.php?page='.$_request['page']), ); return sprintf( '%1$s <span style="color:silver">(id:%2$s)</span>%3$s', /*$1%s*/ $item->user_firstname, /*$2%s*/ $item->id, /*$3%s*/ $this->row_actions($actions)); } function column_cb($item) { return sprintf( '<input type="checkbox" name="%1$s[]" value="%2$s" />', /*$1%s*/ $this->_args['singular'], $item->id ); } function get_columns() { $columns = array( 'cb' => '<input type="checkbox" />', 'user_firstname' => 'user name', 'user_login' => 'user id', 'user_email' => 'email', 'paid_charge' => 'payment', 'additional_member' => 'additional member', 'date' => 'registered date' ); return $columns; } function get_sortable_columns() { $sortable_columns = array( 'user_firstname' => array('u.user_firstname',true), 'user_login' => array('uz.user_login',true), 'user_email' => array('uz.user_email',false), 'paid_charge' => array('ui.paid_charge',false), 'additional_member' => array('ui.additional_member',false), 'date' => array('ui.date',false) ); return $sortable_columns; } function get_bulk_actions() { $actions = array( 'delete' => 'delete' ); return $actions; } function process_bulk_action() { global $wpdb; if( 'delete'===$this->current_action() ) { $id = $_request['id']; $ids = ''; if(is_array($id)) { foreach($id $k=>$v) { $ids .= $v . ","; } $ids = substr($ids, 0, -1); } else { $ids = $id; } if($ids != '') { $wpdb->query( "delete `".$wpdb->prefix."events3` id in ($ids)" ); } } } function prepare_items() { global $wpdb; $query = " select ui.id, u.user_firstname, ui.paid_charge,ui.date, ui.additional_member, uz.user_email, uz.user_login ".$wpdb->prefix."events3 ui inner join ".$wpdb->prefix."user_info u on ui.user_id=u.user_id inner join ".$wpdb->prefix."users uz on u.user_id = uz.id ui.user_id = u.user_id , ui.status = 1"; //echo $query; //exit; $orderby = !empty($_get["orderby"]) ? mysql_real_escape_string($_get["orderby"]) : 'desc'; $order = !empty($_get["order"]) ? mysql_real_escape_string($_get["order"]) : ''; if(!empty($orderby) & !empty($order)) { $query.=' order '.$orderby.' '.$order; } $totalitems = $wpdb->query($query); $perpage = 15; $hidden = array(); $paged = !empty($_get["paged"]) ? mysql_real_escape_string($_get["paged"]) : ''; if(empty($paged) || !is_numeric($paged) || $paged<=0 ) { $paged=1; } $totalpages = ceil($totalitems/$perpage); if(!empty($paged) && !empty($perpage)) { $offset=($paged-1)*$perpage; $query.=' limit '.(int)$offset.','.(int)$perpage; } $this->set_pagination_args( array( "total_items" => $totalitems, "total_pages" => $totalpages, "per_page" => $perpage, )); $columns = $this->get_columns(); $sortable = $this->get_sortable_columns(); $this->_column_headers = array($columns, $hidden, $sortable); $this->process_bulk_action(); $this->items = $wpdb->get_results($query); //echo "<pre>"; //print_r($this->items); //exit; if(!empty($this->items)) { $items = array(); foreach($this->items $item) { if($item->additional_member == "yes") { $item->additional_member = 'yes'; } else if($item->additional_member == 'no') { $item->additional_member = 'no'; } $paid_charge = explode(".", $item->paid_charge); $item->paid_charge = $paid_charge[0]; $items[] = $item; } $this->items = $items; } } } $orderslisttable = new tt_orders_list_table(); $orderslisttable->prepare_items(); ?> <div class="wrap"> <div id="icon-users" class="icon32"><br/></div> <h2>form data</h2> <form id="posts-filter" method="get"> <input type="hidden" name="post_type" value="<?php echo $_request['post_type'] ?>" /> <input type="hidden" name="page" value="<?php echo $_request['page'] ?>" /> <?php $orderslisttable->display(); ?> </form> </div>
Comments
Post a Comment