• Resolved arr0w

    (@arr0w)


    How can I unlock readonly fields for logged in users on the frontend?
    I want logged in users to be able to edit records without using the adminpanel.

    Is that possible?

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

    (@xnau)

    Of course the easiest way to do this is to make them not read only because who else is going to be editing that record?

    If you really do have both logged-in and not-logged-in users editing records, it’s a bit complicated to set up, you need to do the opposite: make the fields read-only for not-logged-in users. This is because read-only fields can’t be updated from the frontend. This is so readonly fields can’t be easily spoofed by altering the form.

    • This reply was modified 7 years, 12 months ago by xnau webdesign. Reason: spelling
    Thread Starter arr0w

    (@arr0w)

    How can I make the readonly fields only appear for not-logged-in users?

    Plugin Author xnau webdesign

    (@xnau)

    OK, so you have people who are not logged in who need to be able to edit a record? If they don’t need to edit, then use the [pdb_single] shortcode to just show them the values.

    If they do need to edit, then they need to use a private link for a page with the [pdb_record] shortcode and the read only fields will appear for them, they just won’t be able to edit them.

    Thread Starter arr0w

    (@arr0w)

    I think we just misunderstood each other.

    Both admins and non-admins should be able to edit the same records.
    Non-admin users shouldn’t have access to edit readonly fields – Only admins/logged-in users.

    I know admins can edit records on the backend, but I have made a record-list for admins on the frontend.

    You said it would be complicated to perform. But not impossible.

    Plugin Author xnau webdesign

    (@xnau)

    OK, what you need to do is switch off the read-only settings on your fields because you can’t save readonly fields from the frontend.

    Next you’ll need a custom template that first determines what kind of user it is then in the loop that displays all the fields, set the “readonly” property to true if you want the current field to be readonly.

    For a simple example, if you wanted to make the ‘first_name’ field readonly, you’d do this:

    <?php if ( $this->field->name === 'first_name' ) $this->field->readonly = true; ?>

    So in your template, you’d check for every field you wanted to be readonly when a non-admin was editing and set the readonly to true.

    Thread Starter arr0w

    (@arr0w)

    Your suggestion got me thinking:

    What if I use jquery to change the input field to text and disables this when a user i logged in.
    Is it possible to give a field its own class?

    I have multible readonly fields that I want to target at once. At the moment I have to call each field by class generated from the name.

    How can I target the fields with a specific class?

    Plugin Author xnau webdesign

    (@xnau)

    If you look at the HTML of the form, you will see that every field is wrapped in a classname that include the name of the field, You can use this to set up your jQuery selectors.

    Thread Starter arr0w

    (@arr0w)

    Yes I’m aware of that.. I just hoped I could put a costom class on a field. The answer was to use the class*=something with jQuery – But thank you!

    The result was to convert the input to static text if the user is not logged in.

    • This reply was modified 7 years, 11 months ago by arr0w.
    • This reply was modified 7 years, 11 months ago by arr0w. Reason: Added some more
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Unlock readonly fields for logged in users’ is closed to new replies.