Wordpress在插入新数据后刷新表

Wordpress refresh table after insert new data

本文关键字:刷新 数据 插入 新数据 Wordpress      更新时间:2023-09-26

我真的不知道这个问题。我创建了新的插件。结构简单:div FreeQuotation_wrap2(显示表格)、div FreeQuotation _wrap3(插入新数据)。但在写入新数据并点击提交后,页面会用旧数据刷新。

当我点击刷新时,我看到信息,它将重新发送数据到数据库。没关系,我用unique来阻止它。现在我看到一张有新记录的新桌子。如何自动制作?

我尝试了3种方法:onSubmit="(不起作用)和javascript(window.location="…")以及trick with session(我得到错误-标头已经由…发送)

<?php
global $FreeQuotation_version;
global $wpdb;
echo $table_name;
global $today_date;
$table_name = $wpdb->prefix . 'free_quotation_kic';
?>
<div class="FreeQuotation_wrap">
    <h2><div class="FreeQuotation_header"></div> FreeQuotation <?php echo $FreeQuotation_version; ?></h2><br>
</div>
<div class="FreeQuotation_wrap2">
    <table class="widefat">
        <?php 
        $FreeQuotation_table = $wpdb->get_results(
        "
        SELECT *
        FROM $table_name
        ORDER BY adding_date DESC
        LIMIT 0 , 10
        "
        ); 
        //nagłówek
            echo '<thead><tr><th> ID </th><th> Quotation </th><th> Author </th><th> Display Date </th><th> Delete </th></tr></thead>';
        //treść
        foreach ( $FreeQuotation_table as $ogresults ) 
        {
            echo '<tr><td>'; 
            echo $ogresults->id; 
            echo '</td><td>'; 
            echo $ogresults->quotation; 
            echo '</td><td>'; 
            echo $ogresults->author;
            echo '</td><td>';
            echo $ogresults->display_date;
                echo '</td></tr>'; 
        }
        echo '<tfoot><tr><th> ID </td><th> Quotation </td><th> Author </td><th> Display Date </th><th> Delete </td></tr></tfoot>';
        ?>
    </table>
</div>
<div class= "FreeQuotation_wrap3">
    <form method="post" action="options.php">
        <?php settings_fields('FreeQuotation_settings_filed'); ?>
        <?php $options = get_option('FreeQuotation_options'); ?>
    </form>
<?php
    global $current_user;
    $ufUserID = $current_user->ID;
    $quotation = $_POST["quotation_textarea"];
    $author = $_POST["autor_text"];
    $display_date = $_POST["display_date"];
    $url = $_SERVER['PHP_SELF'];
    $adding_date = $today_date;
    echo $url;
    if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'updateFeedback' ) {
        $FreeQuotation = $wpdb->insert( 'wp_free_quotation_kic', array( 'quotation' => $quotation, 'author' => $author, 'display_date' => $display_date, 'adding_date' => $adding_date,) );
    }?>
    <a href="<?php echo $url;?>">TUTAJ</a>
    <h3 class="widget-title">Add quotation</h3>
    <form id='reloader' method='post' onSubmit="<?php echo $url;?>">
        <table class="widefat" >
            <thead>
            <tr><th>Quotation</th><th>Author</th><th>Display Date</th></tr>
            </thead>
            <tbody>
            <tr><td>
            <textarea rows="1" cols="100" name="quotation_textarea" required></textarea>
            </td>
            <td>
            <input type="text" name="autor_text" required></input>
            </td>
            <td>
            <input type="text" name="display_date" required></input>
            </td></th>
            </tbody>
            <tfoot>
            <tr><th>
            <input class="button button-primary" type="submit" name="submit" value="submit"/>
            <?php wp_nonce_field( 'updateFeedback' ); ?>
            <input name="action" type="hidden" id="action" value="updateFeedback"/>
            </th></td>
            </tfoot>
        </table>
    </form><br>
</div>
<div class="FreeQuotation_wrap4">
    <h3>Zmiany:</h3>
</div>
<?php 
?>

你能帮我吗?这是我雇佣的第一个问题(我相信这是最后一个…)。通常当我试图写一个问题时,我很快就会找到答案:)现在我花了几个小时处理这个问题,但我看不到任何解决方案。。。

我找到了简单的解决方案——它非常简单,而且很有效。也许这不专业,但我没有任何其他想法。。。

我更改了页面上的顺序。第一个是添加新位置的表格,第二个是现在带有输出的表格。这意味着我更改了两个顺序:

<div class= "FreeQuotation_wrap3">
...
</div>
<div class="FreeQuotation_wrap2">
...
</div>

这是我在stackoverflow.com上的第一个答案;-)