Forum Replies Created
-
In reply to: bbress custom fields, auto-populate topic content
No problem. I found out that I did not need to create that extra function after all. All I had to do was place ‘bbp_topic_content’ in the ajax function. Here is the javascript. I put more code below this.
<script> $(function() { $( "#dialog" ).dialog({height: 550, width: 450}); $( ".submit" ).click(function(){ $.ajax({ type: "POST", url: 'review-meta.php', async:true, dataType: 'json', //assign values to the variables to be passed to the server via data, according to their B position //within the foreach array. See script within loop for jquery window to see how B is derived. data: { B : B, cover : b_cover[B], coverSmall : b_cover_small[B], title : b_title[B], author : b_author[B], published : b_published[B], ISBN : b_ISBN[B], description : b_description[B], pages : b_pages[B], publisher : b_publisher[B]}, success: function(data) { //identify the variables for unique handing on the server side, this is //how the book data gets to the input fields for bbpress forums $("textarea[name='bookCover']").val(data.cover); $("input[name='bookCoverSmall']").val(data.coverSmall); $("input[name='bbp_topic_title']").val(data.title); $("input[name='bookAuthor']").val(data.author); $("input[name='bookPublished']").val(data.published); //$("textarea[name='bookDescription']").val(data.description); $("input[name='bookPages']").val(data.pages); $("input[name='bookPublisher']").val(data.publisher); $("input[name='bookISBN']").val(data.ISBN); $("textarea[name='bbp_topic_content']").val(data.description); //alert(B); }, //error: function(errorThrown){ //alert('error'); //}, }); $( "#dialog" ).dialog( "close" ); }); }); </script>
Here’s how I did variable assignment in a different script, located within the loop where I am generating results. I did not include all the variable as this is long. Also, I am wondering if I could have done some type of auto-indexing instead of having to list each result. Luckily there are only 10, otherwise this would have been crazy.
$( ".submit" ).click(function(){ //get the id number of the button the user selects, which is indexed for each result //the variable B is then decremented 1 from id because javascript arrays begin with [0] if(this.id.indexOf('select')>-1) {var id = (this.id.split(" "))[1]; console.log(id);} B = id - 1; }); //create an array for all 10 results. There is probably a cleaner way to do this var b_cover = [<?php echo json_encode($b_cover[1]); ?>,<?php echo json_encode($b_cover[2]); ?>,<?php echo json_encode($b_cover[3]); ?>,<?php echo json_encode($b_cover[4]); ?>, <?php echo json_encode($b_cover[5]); ?>,<?php echo json_encode($b_cover[6]); ?>,<?php echo json_encode($b_cover[7]); ?>,<?php echo json_encode($b_cover[8]); ?>, <?php echo json_encode($b_cover[9]); ?>,<?php echo json_encode($b_cover[10]); ?>]; //this is the javascript foreach that stores the array values 0 to 9 b_cover.forEach(function(entry){console.log(entry);}); var b_title = [<?php echo json_encode($b_title[1]); ?>,<?php echo json_encode($b_title[2]); ?>,<?php echo json_encode($b_title[3]); ?>, <?php echo json_encode($b_title[4]); ?>,<?php echo json_encode($b_title[5]); ?>,<?php echo json_encode($b_title[6]); ?>, <?php echo json_encode($b_title[7]); ?>,<?php echo json_encode($b_title[8]); ?>,<?php echo json_encode($b_title[9]); ?>,<?php echo json_encode($b_title[10]); ?>]; b_title.forEach(function(entry){console.log(entry);});
Do you want me to include the bbpress custom fields code?
In reply to: bbress custom fields, auto-populate topic contentI solved this. Go to the below link:
https://bbpress.org/forums/topic/bbress-custom-fields-auto-populate-topic-content-2/In reply to: bbress custom fields, auto-populate topic contentThis is a rare event for me; I figured this out within 4 hours of posting it. I am including the solution in case someone else decides they want to do the same thing. I had the input name correct: bbp_topic_content. As I was guessing above, I merely had to create a new function. Below is the variable declaration in javascript, and the function that auto-populates the content field of a new topic:
$("textarea[name='bbp_topic_content']").val(data.description);
add_action ( 'bbp_get_the_content', 'bbp_description_to_topic'); function bbp_description_to_topic(){ $value = get_post_meta( bbp_get_topic_id(), 'bbp_topic_content', true); echo "<p><textarea style='width: 414px; height: 151px' name='bbp_topic_content' value='".$value."'></textarea></p>"; }
You solved it – thanks much! Now I am on to more difficult issues. For example, how to select one of the books and get that information to populate into the fields I created. I have threads open on Stack Overflow, but still haven’t found a solution. Trying to learn how to implement Ajax within jQuery and return results to a php file.
Thanks again for the help. We can close this thread now.
@tharsheblows, thanks for inquiring about this. No, I have not figured it out. Sorry I did not get back to you; I was in Europe traveling on business.
As a temporary fix I had removed the function call to my google books search function from form-topic.php. But I prefer to keep that function call in there. When you were trying to replicate this, I was calling my function via a shortcode.
If you go to my site, and got to “Generations”, then click on “add a book”, you will see the google books search window. Just search for a book in that window, then watch what happens.
Any insight you can give me would be greatly appreciated. There are still many other things I am trying to figure out, but this would be a great step.
Thanks,
Jerry