Form submission problems
-
Hey there,
I am attempting to update some custom user profile fields from a form submission (not from the user profile page itself). The basic premise is that I’m making an rpg-ish game and need to be able to update the user’s experience/level/etc. which I am keeping track of as a user profile field. Anyway, here is probably more code than I need, but in case you guys need to reference it, here is the stuff in my functions.php for the user profile field “experience”:
add_action( 'show_user_profile', 'my_show_extra_profile_fields' ); add_action( 'edit_user_profile', 'my_show_extra_profile_fields' ); function my_show_extra_profile_fields( $user ) { ?> <h3>Extra profile information</h3> <table class="form-table"> <tr> <th><label for="experience">Total Experience</label></th> <td> <input type="text" name="experience" id="experience" value="<?php echo esc_attr( get_the_author_meta( 'experience', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description">Your Total Experience</span> </td> </tr> </table> <?php } add_action( 'personal_options_update', 'my_save_extra_profile_fields' ); add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' ); function my_save_extra_profile_fields( $user_id ) { if ( !current_user_can( 'edit_user', $user_id ) ) return false; update_user_meta( $user_id, 'experience', $_POST['experience'] ); }Here is the code on the page from which I want to update the user profile:
<form id="your-profile" action="<?php bloginfo('template_directory'); ?>/updatemeta.php" method="post"> <p> <input type="text" name="checkuser_id" id="checkuser_id" value="<?php global $current_user; get_currentuserinfo(); echo $current_user->ID; ?>" /> </p> <div style="clear: both;"> <h4>Total Experience</h4> <?php if ( get_the_author_meta( 'userxp' ) ) { ?> <input name="oldxp" id="oldxp" value="<?php the_author_meta( 'experience' ); ?>" type="hidden"> <input name="userxp" id="userxp" value="<?php the_author_meta( 'experience' ); ?>" type="text" readonly> <?php } // End check for experience ?> </div> (Note: You can only submit scores once per day, once you submit the menu will be disabled until tomorrow) <input name="updatexp" id="updatexp" class="btnb" type="submit" value="Update Experience"> </form>and here is the updatemeta.php file to which I am attempting to submit the form:
<?php include 'bloginfo('home')/wp-blog-header.php'; update_user_meta( $_POST['checkuser_id'], 'experience', $_POST['userxp'] ); ?>whenever I attempt to submit the form I get the error: “Fatal error: Call to undefined function update_user_meta() in blahblahblah/updatemeta.php on line 3” I am assuming that my updatemeta.php file is either missing some include that I can’t figure out or it’s in the wrong place (right now it’s in the template file with all my page templates). Anyway, if you knowledgeable people have any insights, I would be incredibly thankful.
Thomas
The topic ‘Form submission problems’ is closed to new replies.