0

Create Option Page

add_action('admin_menu', 'contact_menu');
function contact_menu(){
    add_menu_page(  'Contact Form', 
                    'Contact Form', 
                    'manage_options', 
                    'contact-form', 
                    'view_etries' , 
                    'dashicons-admin-media' );
}

Table Creation & Display

//create table
global $wpdb;
    $table = $wpdb->prefix . "contact_table"; 
    $charset_collate = $wpdb->get_charset_collate();
    $sql = "CREATE TABLE IF NOT EXISTS $table (
        `id` mediumint(9) NOT NULL AUTO_INCREMENT,
        `page_name` VARCHAR(500) NOT NULL,
        `title_name` VARCHAR(50) NULL,
        `full_name` VARCHAR(50)  NULL,
        `email` VARCHAR(50) NOT NULL,
        `phone` VARCHAR(50) NOT NULL,
        `home_select` VARCHAR(500)  NULL,
        `home_price` VARCHAR(500)  NULL,
        `selected_builder` VARCHAR(500)  NULL,
        `comment`  VARCHAR(500) NULL,
        `newsletter` VARCHAR(50)  NULL,
    UNIQUE (`id`)
    ) $charset_collate;";
    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    dbDelta( $sql );
//create table
function view_etries(){
    global $wpdb;
    echo "<div class='contact-admin'>";
    echo "<h1>Form Entries</h1>";
    $mainTable = $wpdb->prefix . "contact_table";
    @$query = $wpdb->prepare("SELECT * FROM $mainTable WHERE %d >= '0'", RID);
    $entries_forms = $wpdb->get_results($query);
    echo "<table class='table table-bordered'  style='width: 100%; text-align: left;'>
            <thead>
                <tr>
                    <th>Page Name</th>
                    <th>Name</th>
                    <th>Email</th>
                    <th>Phone</th>
                    <th>Home Select</th>
                    <th>Price</th>
                    <th>Select Builder</th>
                    <th>Comment</th>
                    <th>Newsletter Subscribe?</th>
                </tr>
            </thead>";
    foreach ( $entries_forms as $entries_form ) {
        if($entries_form->newsletter=='on'){
            $newsletter = 'Yes';
        }else{
            $newsletter = 'No';
        }
        echo "<tr><td>$entries_form->page_name</td><td>$entries_form->title_name $entries_form->full_name</td><td>$entries_form->email</td><td>$entries_form->phone</td><td>$entries_form->home_select</td><td>$entries_form->home_price</td><td>$entries_form->selected_builder</td><td>$entries_form->comment</td><td>$newsletter</td></tr>";
        //echo $entries_form->id . " " . $entries_form->name . " " . $entries_form->email . " " . $entries_form->phone . " " . $entries_form->comment . "<br/>";
    }
    echo "</table></div>";
}

Insert Query

$table = $wpdb->prefix."contact_table";
  $wpdb->insert( 
            $table, 
            array( 
                'page_name' => get_the_title(),
                'title_name' => $_POST["Title"],
                'full_name' => $_POST["FullName"],
                'email' => $EmailAddress,
                'phone' => $CellPhone,
                'home_select' => $CAT_Custom_487441,
                'home_price' => $CAT_Custom_487442,
                'selected_builder' => $CAT_Custom_341776,
                'comment' => $CAT_Custom_487440,
                'newsletter' => $CampaignList_55096
            )
        );

admin Edited question June 4, 2021
Add a Comment