0

although i am new in wordpress.i am trying to insert data from my custom plugin but nothing happen. previously i tried it from showing user profile it succeed but now i am not able to save data. my code for save data in user meta.

<form action="" method="post" enctype="multipart/form-data">
        <h1>Graduation Photo</h1>
        <div>
            <img src="" id="filepreviewimg1" value="<?php echo esc_attr( get_the_author_meta( 'myspace_graduation_image', $user->ID ) ); ?>" alt="image/file" style=" display: none; width: 200px;margin-top: 5px;margin-bottom: 10px;">
        </div>
        <div class="upload-btn-wrapper">
          <button class="btn">Image</button>
          <input type="file" name="myspace_graduation_image" id="myspace_graduation_image" onchange="showImage1.call(this)" />
        </div>

        <h1>Leader Message</h1>

        <label>Leader image</label>
        <div>
            <img src="" id="filepreviewimg2" alt="image/file" value="<?php echo esc_attr( get_the_author_meta( 'myspace_leader_image', $user->ID ) ); ?>"  style=" display: none; width: 200px;margin-top: 5px;margin-bottom: 10px;">
        </div>
        <div class="upload-btn-wrapper">
          <button class="btn">Image</button>
          <input type="file" name="myspace_leader_image" id="myspace_leader_image" onchange="showImage2.call(this)"/>
        </div>

        <label for="leader_message_title">Title</label>
        <input type="text" id="leader_message_title" value="<?php echo esc_attr( get_the_author_meta( 'leader_message_title', $user->ID ) ); ?>" name="leader_message_title" placeholder="Enter leader message title..">
            <div>
                <input type="submit" name="submit" value="Submit">
            </div>

          </form>

THis is my backend code for inser data:

if(isset($_POST['submit'])){
  add_action('edit_user_profile','add_myspace_usermeta');
  add_action('edit_user_profile_update','add_myspace_usermeta');
    function add_myspace_usermeta($user_id){
    if (!current_user_can('edit_user',$user_id)) {
        return false;
    }

    //add to user meta

    add_user_meta( $user_id, 'myspace_graduation_image', $_POST['myspace_graduation_image'] );
    add_user_meta( $user_id, 'myspace_leader_image', $_POST['myspace_leader_image'] );
    add_user_meta( $user_id, 'leader_message_title', $_POST['leader_message_title'] );

}

please help me. Thanks

  • on which hook do you add the form ? – mmm Jul 2 '18 at 5:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.