【问题标题】:Submit contact form to wordpress database将联系表提交到 wordpress 数据库
【发布时间】:2012-03-08 11:23:42
【问题描述】:

我有以下代码,它应该在页面上创建一个表单,当我提交它时,它应该连接到数据库并将日期和表单信息添加到 wp_user_feedback。目前表单甚至没有出现在页面上不知道为什么?

新错误:

Notice: Undefined index: responseFields in /Users/anderskitson/Sites/fiftyfity/wp-content/themes/fiftyfityNew/contact-form

第 33 行的copy.php

<?php function make_user_feedback_form() {
    global $wpdb;
    global $current_user;


        $ufUserID = $current_user->ID;
        $ufResponses = serialize($_POST["responseFields"]);
        if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'updateFeedback' ) {
            $ufDataUpdate = $wpdb->insert( 'wp_user_feedback', array( 'date' => current_time('mysql'), 'responses' => $ufResponses ) );
        }?>
    <ol>
        <form method="post">
            <li>Question 01<br /><input type="text" id="responseFields[]" value="" /></li>
            <li>Question 02<br /><input type="text" id="responseFields[]" value="" /></li>
            <li><input name="submit" type="submit" id="submit" class="submit button" value="Send feedback" /></li>
            <?php wp_nonce_field( 'updateFeedback' ); ?>
            <input name="action" type="hidden" id="action" value="updateFeedback" />
        </form>
    </ol>
    <?php 
}

add_action('the_content','make_user_feedback_form');
?>

【问题讨论】:

    标签: php database forms wordpress


    【解决方案1】:

    您在函数中有表单。你在任何地方调用这个函数吗?

    如果您不打算将它作为函数的一部分,请将最后一个 } 移到开头的 &lt;ol&gt; 上方

    所以,它应该是这样的(如果将其从函数中拉出)

    <?php function make_user_feedback_form() {
     global $wpdb;
    global $current_user;
    
    
        $ufUserID = $current_user->ID;
        $ufResponses = serialize($_POST["responseFields"]);
        if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'updateFeedback' ) {
            $ufDataUpdate = $wpdb->insert( 'wp_user_feedback', array( 'date' => current_time('mysql'), 'responses' => $ufResponses ) );
            }
        }
        ?>
    <ol>
        <form method="post">
            <li>Question 01<br /><input type="text" id="responseFields[]" value="" /></li>
            <li>Question 02<br /><input type="text" id="responseFields[]" value="" /></li>
            <li><input name="submit" type="submit" id="submit" class="submit button" value="Send feedback" /></li>
            <?php wp_nonce_field( 'updateFeedback' ); ?>
            <input name="action" type="hidden" id="action" value="updateFeedback" />
        </form>
    </ol>
    <?php 
        add_action('the_content','make_user_feedback_form');
    ?>
    

    【讨论】:

    • 我认为他打算将表单放入函数中。安德斯,你在哪里添加这段代码?
    • 我移动了 } 并使用 调用了该函数,但是我得到了一个错误,我在上面添加了。
    • 如果您希望表单位于函数内部,请不要移动 }。我的示例仅适用于您希望在函数之外使用它
    • 谢谢!但是,表格现在正在显示;我在它下面收到一个新错误,不知道它是什么意思,我已经在上面发布了。
    猜你喜欢
    • 2016-04-20
    • 2018-12-29
    • 2014-11-01
    • 2014-12-13
    • 2021-12-29
    • 1970-01-01
    • 1970-01-01
    • 2020-12-20
    • 2015-11-03
    相关资源
    最近更新 更多