Title: update field with code
Last modified: December 3, 2019

---

# update field with code

 *  Resolved [guytimes](https://wordpress.org/support/users/guytimes/)
 * (@guytimes)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/update-field-with-code/)
 * I am using “ultimate member” for wordpress, and I have a field called agreement_signed.
   When a logged in user signs an agreement, I want to update the field to “YES”.
   After they sign, i direct them to: …. website .com/user/username/?sign=yes
 * I am not a php coder and I struggled with this for hours and came up with this,
   which works MOST of the time. For whatever reason, it fails about 25% of the 
   time and I don’t know why. It’s ok if you laugh at my code 🙂
 * What am I doing wrong?
    Thanks, Tom
 * function check_agreement_signed () {
 *  $check = $_REQUEST[‘sign’];
    $user_id = get_current_user_id() ; $agreement =‘
   YES’; if(!empty($check) && $check==’yes’) { $result = update_user_meta( $user_id,‘
   agreement_signed’, $agreement); echo “<h2>**<center>Thank you for signing your
   Adoption Agreement. A copy was emailed to you.</center>**</h2>”; } } add_filter(‘
   um_before_form’, ‘check_agreement_signed’, 1, 2 );
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fupdate-field-with-code%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  Plugin Contributor [Champ Camba](https://wordpress.org/support/users/champsupertramp/)
 * (@champsupertramp)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/update-field-with-code/#post-12204807)
 * Hi [@guytimes](https://wordpress.org/support/users/guytimes/)
 * You need to use `add_action` function.
 * Please do try this code snippet:
 *     ```
       function check_agreement_signed () {
   
            $check = $_REQUEST[‘sign’];
            $user_id = get_current_user_id() ;
            $agreement = ‘YES’;
            if( ! empty( $check ) && $check== ’yes’ ) {
              $result = update_user_meta( $user_id, ‘agreement_signed’, $agreement);
              echo “<h2><center>Thank you for signing your Adoption Agreement. A copy was emailed to you.</center></h2>”;
            }
       }
       add_action( ‘um_before_form’, ‘check_agreement_signed’, 1, 2 );
       ```
   
 * Regards,
 *  Thread Starter [guytimes](https://wordpress.org/support/users/guytimes/)
 * (@guytimes)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/update-field-with-code/#post-12208283)
 * Thank you I will try that. What is the difference between add_filter and add_action?
 *  Plugin Contributor [Champ Camba](https://wordpress.org/support/users/champsupertramp/)
 * (@champsupertramp)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/update-field-with-code/#post-12211511)
 * Hi [@guytimes](https://wordpress.org/support/users/guytimes/)
 * There’s no `um_before_form` filter hook that’s declared in the UM plugin.
 * Regards,

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

The topic ‘update field with code’ is closed to new replies.

 * ![](https://ps.w.org/ultimate-member/assets/icon-256x256.png?rev=3160947)
 * [Ultimate Member – User Profile, Registration, Login, Member Directory, Content Restriction & Membership Plugin](https://wordpress.org/plugins/ultimate-member/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ultimate-member/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ultimate-member/)
 * [Active Topics](https://wordpress.org/support/plugin/ultimate-member/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ultimate-member/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ultimate-member/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Champ Camba](https://wordpress.org/support/users/champsupertramp/)
 * Last activity: [6 years, 6 months ago](https://wordpress.org/support/topic/update-field-with-code/#post-12211511)
 * Status: resolved