Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author donmik

    (@atallos)

    With buddypress profile you can create groups of fields. Maybe you can also duplicate edit profile form and show only the group you need.

    Thread Starter Zabelator

    (@zabelator)

    Thanks for the suggestion. I tried to do something like you mentioned, but it still isn’t working quite right.

    I copied the BP Profile editing page and made a page template out of it. It shows the extra section I added, with the edit boxes. (I set it to show the group I added, that is why Id=2 is in line 3).

    This is the code in the page template:
    http://pastebin.com/pnUnmwNg

    The issue I am having now is that when I click the save button, it redirects to a profile groups page. url =(/EDIT PAGE/profile/edit/group/2/ ) EDIT PAGE is the page you edit the form on.

    I just need the form to save, stay on the same page, and display the information they just saved, and possibly have a “form saved” message appear.

    Any additional help would be greatly appreciated as I am still learning WP and PHP.

    Plugin Author donmik

    (@atallos)

    Function responsible of saving changes in edit profile is located inside bp-xprofile/bp-xprofile-screens.php. Line 38

    function xprofile_screen_edit_profile() {

    Maybe you can use this hook: “xprofile_updated_profile”. Use “bp_core_add_message” function to display custom message and then do the redirect you need.

    Thread Starter Zabelator

    (@zabelator)

    Thanks again for your suggestions. I will take a look at these and post what I can get done.

    Thread Starter Zabelator

    (@zabelator)

    I have gotten to the point where I can load the data from the user into the form and view it. When I enter new data and try to submit the form, it reloads the page while still showing the new data but nothing is saved. I refresh the page and the new data is gone.

    Here is my page template:
    http://pastebin.com/hCnF1GyH

    I think it has to be something with the form action, but I haven’t been able to figure it out. Any help is greatly appreciated.

    Thread Starter Zabelator

    (@zabelator)

    Turns out I had a few issues getting this right.

    1. First was the WP_nonce. To solve this I gave it a custom name under the opening <form> tag
      php wp_nonce_field(‘update-user_’ . $user_id, ‘update_’ );

      and made sure it matched the validation at the top of the page in the PHP.

      if ( wp_verify_nonce( $_REQUEST[‘update_’], ‘update-user_’ . $user_id ) )/li>

    2. Next I added a very simple custom function to save the page:
      function save_page($user_id) {

      if ( current_user_can(‘edit_user’,$user_id) )
      update_user_meta($user_id, ‘my_custom_field’, $_POST[‘field_33’]);
      }

      add_action(‘personal_options_update’, ‘save_page’);

    3. After that it took some investigating, but this line was failing:
      /* Update user with fields from $_POST and get response. */
      $response = edit_user( $user_id );

      Once I remoeved it from my page template, and tested it out, the custom page worked like a charm.

    It now loads, dispays, and saves BP Xprofile data. And even displays the error/confirmation messages. Thanks again for pointing me in the right direction.

    And here is my final page template for anyone interested:
    http://pastebin.com/wcvc3m7z

    Thread Starter Zabelator

    (@zabelator)

    Turns out the Function part in step 2 isn’t even needed. I was thinking I was going to need it, but when I set the input at the bottom of the form to:

    <input type=”submit” value=”update” class=”button-primary” id=”submit” name=”submit”>

    It doesn’t even have to use that custom function.

    Plugin Author donmik

    (@atallos)

    Glad to see you solve it! Great work!

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

The topic ‘Custom Fields on New Page’ is closed to new replies.