using update_user_meta in form to set and get custom meta

You need to pull your meta_data from WP and fill that info into the form… like so:

function my_form_function() {
global $current_user;

$low_price = get_user_meta( $current_user->ID, '_low_price', true);
$medium_price = get_user_meta( $current_user->ID, '_medium_price', true);
$high_price = get_user_meta( $current_user->ID, '_high_price', true);

?>
<form name="setPrices" action="" method="POST">

<fieldset>
<label for="lowPrice">Value 3:</label>
<input type="text" id="lowPrice" name="lowPrice" value="<?php echo $low_price; ?>" />
</fieldset>

<fieldset>
<label for="mediumPrice">Value 2:</label>
<input type="text" id="mediumPrice" name="mediumPrice" value="<?php echo $medium_price; ?>" />
</fieldset>

<fieldset>
<label for="highPrice">Value 1:</label>
<input type="text" id="highPrice" name="highPrice" value="<?php echo $high_price; ?>" />
</fieldset>

<button type="submit">Save</button>
</form>

<?php
$low_price = $_POST['lowPrice'];
$medium_price = $_POST['mediumPrice'];
$high_price = $_POST['highPrice'];

update_user_meta( $current_user->ID, '_low_price', $low_price); 
update_user_meta( $current_user->ID, '_medium_price', $medium_price);
update_user_meta( $current_user->ID, '_high_price', $high_price);

}

Leave a Comment