Title: Form submission problems
Last modified: August 19, 2016

---

# Form submission problems

 *  [LDDConsulting](https://wordpress.org/support/users/suffrage/)
 * (@suffrage)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/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

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [LDDConsulting](https://wordpress.org/support/users/suffrage/)
 * (@suffrage)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/form-submission-problems/#post-1747249)
 * Anyone? I could really use some help on this.
 *  Thread Starter [LDDConsulting](https://wordpress.org/support/users/suffrage/)
 * (@suffrage)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/form-submission-problems/#post-1747372)
 * Ple-ase Halp 🙂
 *  Thread Starter [LDDConsulting](https://wordpress.org/support/users/suffrage/)
 * (@suffrage)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/form-submission-problems/#post-1747389)
 * Okay, now i’m trying to do it with ajax, here is the jquery stuff I have on my
   template page
 *     ```
       <script type="text/javascript">
       jQuery(document).ready(function(){
       	var userid = jQuery('#checkuser_id').val();
       	var exp = jQuery('#userxp').val();
       	jQuery("#yourprofile").submit(function()	{
       				var data = {
       					action: 'my_save_userxp',
       					userxp: exp,
       					checkuser_id: userid
       				};
       				jQuery.post("<?php echo admin_url('admin-ajax.php'); ?>", data,
       				function(response){
       					alert('Got this from the server: ' + response)
       				});
       	});
       });
       </script>
       ```
   
 * here is the form I am submitting:
 *     ```
       <form id="yourprofile" action="" 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( 'experience' ) ) { ?>
       <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 what i added to functions.php
 *     ```
       add_action('wp_ajax_my_save_userxp', 'my_save_userxp_callback');
       function my_save_userxp_callback() {
       $user_id = $_POST['checkuser_id'];
       $userxp = $_POST['userxp'];
       global $wpdb;
       update_user_meta( $user_id, 'experience', $userxp );
       }
       ```
   
 * Now when I submit it’s just reloading the page and not saving the userxp stuff.
   Please, please, if anyone can help with this it would be incredibly useful. Thanks

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Form submission problems’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 1 participant
 * Last reply from: [LDDConsulting](https://wordpress.org/support/users/suffrage/)
 * Last activity: [15 years, 7 months ago](https://wordpress.org/support/topic/form-submission-problems/#post-1747389)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
