Home Forums Plugin Support WP User Frontend Pro Populate hidden field with database value

This topic is: resolved

This topic contains 5 replies, has 2 voices, and was last updated by  Tareq Hasan 5 years, 2 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #16039

    ProUser
    Participant
    Post count: 17

    I am trying to come up with a way to “lock” the post title and content fields on a form so that the data is not changed.

    I am using one form to add new posts and that form has normal fields. However, on the edit form I don't want the user to change anything except the post tags. I am trying to make the form save the record with only the tags changed?

    What, exactly, should I type into the hidden field so that it maintains the current value in the data base. Whatever I enter is saved as a text entry (i.e. the text “post_title”) and not the db value.

    Or if I need to add a function to functions.php, please share the code with me that does this.

    I would greatly appreciate your help as I have been trying to sort this out for several days now.

    Thanks!

    #16041

    Tareq Hasan
    Keymaster
    Post count: 2831

    May be you can make the post title and the post content as a read only field by using jQuery/JavaScript. That way they wouldn't be able to update those fields.

    I haven't tried it yet, when I do, I'll post the codes here.

    #16058

    ProUser
    Participant
    Post count: 17

    THANK YOU, Tareq! That would be greatly appreciated as I am not familiar with JavaScript coding and and I've been struggling to resolve this for about a week…. The ability to allow registered users to add tags to other author's post/images but no other fields. I feel I am spinning in circles looking for ways to accomplish this. ๐Ÿ™‚

    #16096

    Tareq Hasan
    Keymaster
    Post count: 2831

    Paste this code in your themes functions.php

    [php]
    function wpufe_lock_post_fields( $form_id ) {
    if ( $form_id == ‘6' ) {
    ?>
    <script type="text/javascript">
    jQuery(function($){
    $(‘input#post_title').attr(‘readonly', ‘readonly');
    $(‘textarea#post_content').attr(‘readonly', ‘readonly');
    });
    </script>
    <?php
    }
    }

    add_action( ‘wpuf_edit_post_form_bottom', ‘wpufe_lock_post_fields' );
    [/php]

    Change the form ID in that code with your form id.

    Note: It'll not work if the post content field has rich textarea.

    #16120

    ProUser
    Participant
    Post count: 17

    Thank you for the javascript snippet. It worked beautifully. One last, unexpected problem with this. I made an assumption that I would be able to lock the image upload and featured image fields the same way but have been unsuccessful. Could you please tell me how to do that? I've been trying all day and no luck (except bad) :(.

    Many thanks to you again.

    #16135

    Tareq Hasan
    Keymaster
    Post count: 2831

    I think you can't disable the image field with this, sorry!

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Populate hidden field with database value’ is closed to new replies.