Jump to content

Custom Page field in user template won't fully change


adrian
 Share

Recommended Posts

I have set up a custom field in the user template to record the user's organization. This is a page field select. If I change the selected item and then save the change appears to stick, but when I query the value with the api in my template page code, it always returns the old value. BUT, if I select the blank entry (at the top of the select list), save it, then select the entry I really want and then save again, it sticks and returns the proper value via the API. I have done this several times now and always the same.

Let me know if I can provide any additional info to help debug this one.

Link to comment
Share on other sites

Hi Wanze,

I am using this to get the name of the custom organization field in the user template:

    $u = $users->get($user->name);
    $organization = $u->organization->first()->name;

Let me know if there is anything else I can provide.

Link to comment
Share on other sites

I can't reproduce. 

The only thing I can imagine is that you have (according your code) a "multiple pages" page type, but using a single "Select" as input?

This can mess up thing if you changed those setting at one point of time. 

Try changing the inputtype to "ASMSelect" and look at what is there. If there's more than 1, delete them and change your page field to be only "single page" if you really only need single select.

  • Like 1
Link to comment
Share on other sites

Soma - thank you - that was the problem - I guess I hadn't paid close enough attention to the "Dereference in API as" options. Switching to "Single page (Page) or empty page (NullPage) when none selected" and then removing the first() from my code seems to have things sorted. I was actually confused by the need for first() - now I know why so thanks :)

Link to comment
Share on other sites

Glad you solved it!

Just a little remark:

    $u = $users->get($user->name);
    $organization = $u->organization->first()->name;

No need for the first line, in your templates you already have a variable $user for the current user:

$organization = $user->organization->first()->name;


Cheers

  • Like 1
Link to comment
Share on other sites

Good tip, thank you - I think at one point I was actually wanting the user's name assigned to $u, rather than their id, but turns out I am not using that now anyways, so $user-> works a treat.



Although come to think of it, there would still have been no need for the "$users->get" - not sure why I used it :)

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...