Populate hidden field with database value

This topic contains 5 reply and 2 voices, and was last updated by Tareq Hasan 10 years ago
Viewing 5 Posts - 1 through 5 (of 5 total)
Author Posts
March 1, 2014 at 11:12 pm 16039
Tareq Hasan 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!
March 2, 2014 at 3:37 am 16041
Tareq Hasan Tareq Hasan

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.

March 2, 2014 at 7:51 pm 16058
ProUser ProUser

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. 🙂

March 3, 2014 at 12:47 pm 16096
Tareq Hasan Tareq Hasan

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.

March 4, 2014 at 4:32 am 16120
ProUser ProUser

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.

March 4, 2014 at 2:39 pm 16135
Tareq Hasan Tareq Hasan

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

Viewing 5 Posts - 1 through 5 (of 5 total)