• Resolved tonvandervalk66

    (@tonvandervalk66)


    This shortcode:
    [pods name=”user” form=”1″ fields=”vakx, vaky, vakz”]
    shows the form I want, but it does not save. I get the following error:
    User data is required, but wrong or empty

    The shortcode builder from the menu did not work, so I do not really trust it. It suggests I need to add a slug.
    [pods name=”user” slug=”tony” form=”1″ fields=”vakx, vaky, vakz”]
    This shortcode turns out nothing at all.

    What I want to achieve is that the logged in user can edit some custom fields of his own profile. What shortcode do I need?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Jim True

    (@jimtrue)

    Thanks for the additional information, @tonvadervalk66

    Looks like you’ve extended the User WordPress Object. I’ll be honest with you; User’s aren’t really designed for front-end editing, since you’d need to protect the form to not be shown to someone who wasn’t logged in and you’d need to dynamically populate the id (user’s don’t have ‘slugs’) for the form.

    We have Special Magic Tags that provide dynamic values to where clauses and other portions of the shortcode, but I”m not sure they can be used in the id= parameter in the shortcode.

    I’m not at home at the moment so can’t test this one, but if you’ll give me until tomorrow, I can setup a configuration like yours and test a shortcode and see if works properly and report back.

    Plugin Contributor Jim True

    (@jimtrue)

    You’d be looking at the {@user.any} Special Magic Tag, specifically {@user.id}. I’m thinking where="ID = {@user.id}". I just need to confirm that will work to load the current user without requiring the id= parameter to be included.

    Thread Starter tonvandervalk66

    (@tonvandervalk66)

    Thank you, I tried this shortcode:
    [pods name=”user” form=”1″ where=”ID = {@user.id}” fields=”leeftijd”]

    I got this result:
    Database Error; SQL: SELECT DISTINCT t.* FROM wphy_users AS t WHERE ( ( ID = {@user.id} ) AND ( t.user_status = 0 ) ) ORDER BY t.display_name, t.ID LIMIT 0, 15; Response: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘@user.id} ) AND ( t.user_status = 0 ) ) ‘ at line 7

    Next I tried:
    [pods name=”user” form=”1″ where=”{@user.id}” fields=”leeftijd”]
    and got exactly the same error.

    Plugin Contributor Jim True

    (@jimtrue)

    There’s a configuration step you have to do in your wp-config.php to allow the dynamic fields to work. It’s noted in that Special Magic Tags docs linked above.

    That explains the first error. Your second where would not work because where clauses are always some kind of equality statement, like id=5. The {@user.id} is ideally supposed to convert to the logged in users I’d before being sent into the shortcode. That’s what I’ll be testing when I get home later tonight.

    Thread Starter tonvandervalk66

    (@tonvandervalk66)

    I updated the wp-config file with the given code and now I can save the form fields succesfully. That’s another step forward!

    However when inspecting the field in the userprofile from the backend I see they did not get updated. Neither for the admin nor for a subscriber.

    Second I need the default values for the fields in the extended user fields pod to retrieve the current values. Could I use the same Special magic tag for that? {@user.id}

    Plugin Contributor Scott Kingsley Clark

    (@sc0ttkclark)

    You can use [pods id="{@user.ID}"] format if you enable shortcode special tag evaluation in wp-config.php with define( 'PODS_SHORTCODE_ALLOW_EVALUATE_TAGS', true );

    It’s not enabled by default because the special magic tags allow other server-related output beyond just the current user ID.

    Thread Starter tonvandervalk66

    (@tonvandervalk66)

    Alright, I used this shortcode and it works now
    [pods name=”user” form=”1″ where=”id={@user.id}” fields=”fielda, fieldb, fieldc”]

    In the pod settings I entered the corresponding field magic tags like {@user.fielda} and now these custom user fields can be loaded and saved from the frontend. That was my goal and you guys helped me to achieve it.

    I am truly impressed. Thank you!

    Plugin Contributor Jim True

    (@jimtrue)

    @tonvandervalk66 Very happy that worked for you! You beat me to testing this myself, though I’m still going to because we do need to confirm that just the id="{@user.id}" works as well as the where clause.

    You do still want to make sure that this form can be restricted to logged in users. I’d suggest looking at Members plugin by Justin Tadlock. You can easily restrict a WP Page with a shortcode in it to be only viewable by logged in users, or you can wrap our shortcode with one from his plugin to restrict to only logged in users.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘error saving user data’ is closed to new replies.