Show field in frontend but not allow to edit by the user

Support General Show field in frontend but not allow to edit by the userResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #14285
    proyectohappyweb@gmail.com[email protected]
    Participant

    Hello,

    There exist a setting field (text field for example) that show the field in the frontend but don't allow editing by the user?

    I have reviewed this page but I have not seen this option.
    https://docs.metabox.io/field-settings/

    Thanks

    #14325
    Anh TranAnh Tran
    Keymaster

    Hi Sergio,

    Yes, it can be done with a condition like this:

    [
        'type' => 'text',
        'id' => 'field_id',
        'name' => 'Text field',
        'disabled' => ! is_admin(), // This disables editing in the front end.
    ]
    #14330
    proyectohappyweb@gmail.com[email protected]
    Participant

    ooh perfect!!! Many thanks.

    #14352
    proyectohappyweb@gmail.com[email protected]
    Participant

    Hello,

    I have a proble using:
    'disabled' => !is_admin(), // This disables editing in the front end.

    With a meta box with:
    'storage_type' => 'custom_table', // Important

    Is that all fields are saved well in the custom table except the fields that I put 'disabled' => !is_admin()...

    Have you detected if it is a general error? Or does it just happen to me?

    I try to put this like this
    'attributes' => array(
    'disabled' => true,
    ),
    But it doesn't matter, not save the value...

    Thanks.

    #14355
    proyectohappyweb@gmail.com[email protected]
    Participant

    Hello,

    I try this:
    'readonly' => true,
    and it run ok!! Users can't edit the field and the value is saved in the custom table.

    Sergio

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