用户登录后保存自定义表单数据

时间:2013-05-04 作者:mit

这是我第一页上的表格。我必须管理,如果用户没有登录,在这种情况下,提交表单后的行动是登录页面。

<?php/** Template Name: Form */ 
get_header(); ?>

<form id="new_post" <?php do_action(\'post_edit_form_tag\'); ?> name="new_post" method="post" action="<?php if ( is_user_logged_in() ) { } else { echo \'http://localhost/manage/login\'; } ?>">
<p><label for="title">Project Title</label><br />
<input type="text" id="title" value=""  name="title" /></p>
<p><label for="Category">Category:</label><br />
<?php wp_dropdown_categories(\'type=post&show_count=0&selected=-1&hierarchical=1&depth=1&hide_empty=0&exclude=0&show_option_none=Select Category&taxonomy=category\');?></p>
<p><label for="description">Project Description</label><br/>
<textarea id="description"  name="description" ></textarea></p>
<p><label for="post_date">submit date:</label></br>
<input type="text" value="" tabindex="5" size="16" name="post_date" id="post_date" /></p>
<p align="right"><input type="submit" value="Publish" tabindex="6" id="submit" name="submit" /></p>
<input type="hidden" name="action" value="new_post" />
<?php wp_nonce_field( \'new-post\' ); ?></form>

<?php get_footer(); ?>
提交此表单后,我将在登录页面上发送帖子值,在用户登录后,我想用UserID保存帖子。此页面代码:

<?php
/**
 * * Template Name: Login Page
*/
get_header(); ?>

<?Php
// Values Comin From 1st Page
$title =  $_POST[\'title\'];
$description = $_POST[\'description\'];
$category = $_POST[\'cat\'];
$date = $_POST[\'post_date\'];

if (isset ($_POST[\'login\'])) {
    $new_post = array(
                         \'post_author\'    => LOGGED IN USERID,
                         \'post_title\'    => $title,
                         \'post_content\'  => $description,
                         \'post_status\'   => \'publish\',
                         \'post_type\' => \'post\' 
                        ); 
                        //save the new post
                          $pid = wp_insert_post($new_post);

                        add_post_meta( $pid, \'category\', $category , true );
                        add_post_meta( $pid, \'date\', $date, true );    
    }
?>

        <form id="login" action="login" method="post" name="new_post">
        <h1>Site Login</h1>
        <p class="status"></p>
        <label for="username">Username</label>
        <input id="username" type="text" name="username">
        <label for="password">Password</label>
        <input id="password" type="password" name="password">
        <input class="submit_button" type="submit" value="Login" name="login">  
        <?php wp_nonce_field( \'ajax-login-nonce\', \'security\' ); ?>
        <input type="hidden" name="action" value="new_post" />
        <?php wp_nonce_field( \'new-post\' ); ?>
    </form>
<?php get_footer(); ?>
这就是我正在使用的代码。

1 个回复
SO网友:kaiser

只需检查$_POST 登录页上的值。

add_action( \'login_head\', \'wpse_98289_custom_form\' );
function wpse_98289_custom_form()
{
    var_dump( $_POST );
}
您可以在那里搜索指定为的值name/id 属性,然后开始在登录表单中填充自定义/其他字段。

结束

相关推荐

列出分类法:如果分类法没有POST,就不要列出分类法--取决于定制的POST-META?

这可能很难解释,我不知道是否有解决办法!?我有一个名为“wr\\u event”的自定义帖子类型和一个名为“event\\u type”的分层自定义分类法。自定义帖子类型有一个元框,用于event_date 并且与此帖子类型关联的所有帖子都按以下方式排序event_date. 我在循环中有一个特殊的条件来查询event_date 已经发生了-在这种情况下,它没有显示,但只列在我的档案中。就像你可以使用wp_list_categories() 我编写了一个自定义函数,它以完全相同的方式列出所有分类术语。现在