• Hi there,
    I was wondering if it is possible to add with javascript an unchangeable value (“comments”) to a custom field in the WordPress comment area.
    In this moment I have this situation:
    IMAGE

    I would like the field N.3 to be readonly and have a default value attribute that can not be modified.

    The id of the third field is #textar.

    Any idea? Thank you in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter FreddyAZ

    (@freddyaz)

    thank you for the prompt answer

    Moderator bcworkz

    (@bcworkz)

    We normally discourage bumping here, but seeing that you patiently waited 6 months (!!) before trying again, you are excused! ??

    While it’s possible to use javascript as you describe, it’s not very reliable since the user can easily disable javascript. It’s better to handle this server side where the user has no control over the processing. In this case use the ‘preprocess_comment’ filter to change whatever the user submitted to whatever value you want it to always be.

    It’s rather rude to solicit data from a user, then ignore it and substitute your own value, IMHO of course. You should alter the form field so that it’s not even a field any longer. Then you don’t have to worry so much about the preprocess_comment hook, though it’s still good insurance since a savvy user could submit a value that WP is expecting even if there is no form field to fill in.

    Anyway, to alter the field, use the “comment_form_field_{$name}” filter to output something besides a text input field. {$name} is the name attribute of the field, which may not be the same as the ID, though often is the same. This is assuming your theme uses comment_form() to output the form. If it does not, you’ll need to alter what your theme does do in some manner. This typically means creating a child theme.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Fixed value (readonly) in a custom field in the comment area’ is closed to new replies.