简体   繁体   English

插入新数据后Wordpress刷新表

[英]Wordpress refresh table after insert new data

I really don't have any idea with this problem. 我真的不知道这个问题。 I create new plug-in. 我创建新的插件。 Structure is easy: div FreeQuotation_wrap2 (display the table), div FreeQuotation_wrap3 (insert new data). 结构很简单:div FreeQuotation_wrap2(显示表),div FreeQuotation_wrap3(插入新数据)。 But after write new data and click submit page is refresh with old data. 但是在写入新数据并单击提交页面后,将使用旧数据刷新。

When I click refresh I see information that it will resend data to database. 单击刷新时,我看到的信息是它将重新发送数据到数据库。 It's ok- I prevent it with unique. 没关系-我会以独特的方式阻止它。 Now I see new table with new record. 现在,我看到带有新记录的新表。 How can I make it automatically? 如何自动制作?

I try 3 methods: onSubmit="" (doesn't work) and javascript (window.location = "...") and trick with session (i get error - headers already sent by...). 我尝试3种方法:onSubmit =“”(不起作用)和javascript(window.location =“ ...”),并欺骗会话(我收到错误-标头已经由...发送)。

<?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 
?>

Can you help me? 你能帮助我吗? It's my first question hire (and I believe that the last...). 这是我的第一个问题招聘者(我相信最后一个问题)。 Usually when I try to write a question I find the answer quickly :) Now I spend few hours with this problem and I doesn't see any solution... 通常,当我尝试写一个问题时,我会很快找到答案:)现在,我花了几个小时解决这个问题,但没有任何解决方案...

I find simple solution - it's very easy and it's work. 我找到了简单的解决方案-这很容易,而且很有效。 Maybe it's not professional but I don't have any other idea... 也许它不专业,但我没有其他想法...

I change the order on the page. 我在页面上更改顺序。 First is the form to add new position, the second is now the table with output. 第一个是添加新位置的表单,第二个是现在带有输出的表格。 It means that I change two order: 这意味着我更改了两个顺序:

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

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

And this is my first answer on stackoverflow.com ;-) 这是我在stackoverflow.com上的第一个答案;-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM