向前端注册表单添加额外的字段

时间:2012-09-03 作者:Rob

我一直在四处阅读并寻找前端注册表格(not using plugins!) 遇到这个-http://net.tutsplus.com/tutorials/wordpress/quick-tip-making-a-fancy-wordpress-register-form-from-scratch/

    <div id="register-form">
    <div class="title">
        <h1>Register your Account</h1>
        <span>Sign Up with us and Enjoy!</span>
    </div>
        <form action="<?php echo site_url(\'wp-login.php?action=register\', \'login_post\') ?>" method="post">
        <input type="text" name="user_login" value="Username" id="user_login" class="input" />
        <input type="text" name="user_email" value="E-Mail" id="user_email" class="input"  />
            <?php do_action(\'register_form\'); ?>
            <input type="submit" value="Register" id="register" />
        <hr />
        <p class="statement">A password will be e-mailed to you.</p>


        </form>
    </div>
这几乎是我所需要的一切,但在球场方面还缺少一些东西。是否可以在前端注册表单中添加额外字段,这些字段将保存并显示在后端?

1 个回复
SO网友:Cristian Dumitru Antohe

您可以在以下网址阅读内容广泛的教程:

http://www.cozmoslabs.com/1012-wordpress-user-registration-template-and-custom-user-profile-fields/

基本上,这是您将用来将它们添加到后端的内容:

add_action( \'show_user_profile\', \'show_extra_profile_fields\', 10 );
add_action( \'edit_user_profile\', \'show_extra_profile_fields\', 10 );

function show_extra_profile_fields( $user ) { ?>
    <input type="text" name="twitter" value="<?php echo esc_attr( get_the_author_meta( \'twitter\', $user->ID ) ); ?>" />
<?php }
并在用户或管理员更新配置文件时保存它们:

add_action( \'personal_options_update\', \'save_extra_profile_fields\' );
add_action( \'edit_user_profile_update\', \'save_extra_profile_fields\' );

function save_extra_profile_fields( $user_id ) {
    if ( !current_user_can( \'edit_user\', $user_id ) )
        return false;
    update_usermeta( $user_id, \'twitter\', $_POST[\'twitter\'] );
}
下一步是将这些额外字段添加/保存到正在构建和使用的表单中:

update_usermeta( $new_user, \'twitter\', esc_attr( $_POST[\'twitter\']  ) );    
在用户注册时从前端保存它们。

结束

相关推荐

Front-End Post Submission

我正在尝试添加一个表单,用户可以从前端提交帖子。我正在学习本教程:http://wpshout。com/wordpress从前端提交帖子/我正在做的是添加this code 到我的一个页面模板。表单显示正常,但当我单击“提交”按钮时,它会显示“Page not found error“”许多评论者说这不起作用。谁能给我指出正确的方向吗?代码是否不完整?有缺陷吗?我做错什么了吗?谢谢Towfiq I。