Custom Field has no standard value of the same ID

Support General Custom Field has no standard value of the same ID

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #48065
    Christian KleeChristian Klee
    Participant

    Hello,

    I used the custom fields to create different event forms. The fields would have user information like user company name from past events prefilled. I created this field with always the same ID like user_company or even the field ID first_name would work to change the user name.

    Now these standard values are not prefilled anymore.
    It still works if I use the PHP Code and add for example rwmb_meta( 'user_company', [ 'object_type' => 'user' ], $current_user_id ) as the std value. But that would require to use always PHP code and modify by hand the standard value.

    New is that I get a waring if I type the same ID:
    This ID already exists in the field group 'User information', please change it or edit that field group to avoid duplication.
    So I guess with this change, my solution stopped working?
    Is there a way to avoid using PHP export every time?

    #48084
    PeterPeter
    Moderator

    Hello Christian,

    Using one field ID for different fields is not a good way. You should have a unique ID per custom field.
    Then if you want to show the last saved field value in a new form as a default value, you can use the PHP code for each field.

    Following the documentation https://docs.metabox.io/field-settings/

    #48523
    Christian KleeChristian Klee
    Participant

    Okay but is there now no way to get previous information saved in a general user field?
    So for example I built an event registration where for example the standard WordPress fields first_name was displayed with the id first_name. So previously if a added a new textfield with the ID first_name the name was displayed and a user could change this user field directly in the event registration.
    With the update it is not possible anymore, only if I use PHP to make at least the default value prefilled.

    So every time a new event has to be created a programmer has to make changes in the functions.php or do I miss something?

    #48525
    PeterPeter
    Moderator

    Hello,

    If you want to check the previous value of a field, please use the action hook rwmb_{$field_id}_after_save_field. Refer to the documentation https://docs.metabox.io/actions/rwmb-after-save-field/

    I hope that helps.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.