<?php bp_activity_id() ?> in buddypress, anyone up to scratch? - php

I have been trying to sort this problem out for the last few days, here is an overview of my problem relating to
<?php bp_activity_id() ?>
I have 2 comment forms for a gallery plugin in buddy press, the first appears if there are no comments, and it 'creates' a activity it, the 2nd form appears if a comment has ever been made to and has the <?php bp_activity_id() ?> attached it it.
I would like to know how to automatically create a activity item as the first form cannot use features such as favorite or like as there is no id to associate with. I would like the 2nd form to be filled with an id, or in worst case scenario is it possible for some jquery/javascript to automatically add a comment and remove it ONCE (one time only) so that there is an ID? I can find more info if required, any really appreciate any help given!

$newActivity = bp_activity_add($args); // you dont NEED args, but you can pass them.
// $newActivity = the new activity's ID.
Source: http://www.buddydex.info/buddypress/bp-activity/bp_activity_add/

Related

Pass a unique reference of a clicked element via AJAX

The title is somewhat confusing, I'm not sure how to word it right as a title.
I'll try to explain better:
I have a forum page, of course as in every other forum elsewhere you can comment on posts. Being able to delete what you wrote is something I should include.
To do this I was planning on setting up a separate page that deletes the comment and using AJAX to do it seamlessly. However, I would need the specific reply ID to delete the one the user is intending to delete.
Below is a link to a picture. The picture demonstrates several comments being posted, obviously they all have separate id's in the database, I'm just not sure how to get the proper one.
So by only a click I need to retrieve the reply ID, any help is appreciated.
you can add data-id="XXX" to element. and access through the class
$('.yourClass').click(function(event) {
var id = $(this).attr('data-id');
console.log(id);
});
Check in your browser console you got the ID
Based on what you just explained, you can attach an attribute to your comment while adding it in the first place like
<div class="single-comment">
<a data-reply-id='23'>Click me, I am a comment!</a>
</div>
This will allow you to reference the data-id using ajax to get back its value and then POST it.
Does that make sense a bit?
I do think Martin Kuchyňár is saying the same.

php html dynamically add to end of list items

I have some data on the server side in a database like Person Info.
I'd like to do the following when the user first views the page: show e.g 3 person info on list like placement.
I can do this by write query for read from database and write "for" in php
and write html code and echo to fill 3 list item.
Next now I need add a link like "more persons" below this tree output and when user clicks this link PHP will show other Persons Info at the end of previous 3 person info without refresh page or redirecting.
How can I do that?
This is an ajax job, you will need to pass the last id of the last person and get the next lot. Anyway ajax - so look into jquery - should make it an easier job.
What you need to use is ajax. I will suggest using jquery for ajax because it will let you get started quickly.
https://learn.jquery.com/ajax/
Hope this helps.

PHP holding session to new page with multiple links going to same new page

I have a project for school that I am working on where I have a table of different parts. In the last column of each row is an "Order" where they all link to orders.php page. Each link is for a different part, though, and so I want my variables to echo on the orders.php page for the correct link clicked. I have no idea how to approach this, but it must be done this way for the class and my professor is rather useless in terms of helping students.
Basically, if I click the "Orders" link in the "Batteries" row, I want the orders.php page to show $partname = Batteries, $price = (Battery Price) ... I really can't even figure out how to get each variable to be set once that link is clicked.
Thanks a bunch for any help please.
i had a hard time trying to understand your question but i think this may help:
you can use GET method to give information to the orders.php lie this:
in the original page you can have something like:
Battery
And in the orders.php:
$partname = $_GET["partname"];
$price = $_GET["price"];
i really hope that this is waht youre looking for. for more info google PHP GET Method.

Tag-like skills in a user profile with a HABTM relationship

In the web application I'm building a user has a profile where they can list their skills. I would like the kind of functionality StackOverflow has when making posts, where you can type tags into the tag input and select ones that already exist, and create them if they don't already exist.
At the moment, I've got a select box appearing on the page with with the id of the users current skills as values. I'm achieving this by doing:
// ProfilesController.php
$skills = $this->Profile->ProfilesSkill->find('list');
// edit.ctp
<?php echo $this->Form->input('Skill', array('value' => $skills)); ?>
I've got no idea how to progress further, though. First of all, the name field for the skills should be shown instead of their id, which I'm confused about because by Cake's convention it will use the name field by default, even though it's not. And secondly when I enter my skills into my profile Cake should automatically make all the required entries in the profiles_skills table. How can I make that work?
The solution is pretty straight forward, though it's pretty much work.
First you'll need a Tag-System. You could build one on your own (like any habtm-relation), or use a plugin like https://github.com/CakeDC/tags
For the second part, the function is called "Autocomplete". It's basically a ajax call every time you enter a letter in a form field. There are a bunch of tutorials out there, e.g: http://blogfreakz.com/cakephp/cakephp-jquery-autocomplete-tutorial/
Hope this points you in the right direction

php Form in steps (autosave after step 2)

I'm doing a project and i'm stuck, Hoping someone can help me with this part of my project please :)
In trying to create a simple classifieds section on my website, I had a form for various information which worked fine, then trying to add images to the database i fell into a problem as the listing wasn't created so the images wouldn't tie in.
So i decided to do a form with 4 steps...
Step 1, choose category, step 2, fill in description, step 3, add photo's, step 4, View listing and confirm it.
Please could someone help me as i'm stuck.
What i would like is...
Step one. Choose category
Step two. Fill in title and description
(Then on clicking to step three it will save the data from steps one and two to mysql database. This is where i'm stuck)
Step three. Add pictures
Step four. Review listing and confirm it. (Will activate in db)
The steps i downloaded from code canyon as i thought this would be an easier and user friendly way.. :)
I look forward to your replies and hope i've given enough information:)
Thank you!
You can do either using AJAX or php sessions.
Here is the AJAX way
function autosave() {
new Ajax.Request('autosave.php',
{
method: 'post',
parameters: {id: $('id').value, save_text: $('myInput').value},
});
}
Now call this function with some Interval.
Other way is you need to place you code in php session and you need to habdle it like - every action you need to save your session data, sameway you need to load if you do back and forward.
Provide more details about php version, some forms, fields and database, I will edit my answer
Since you're new to PHP I'll give you an idea of what to look for. If your page doesn't use AJAX then validate the post data at each submission. If the post data is valid then save it into the session (use the $_SESSION superglobal) and save it to the database at whichever step you need and wipe out the data you just placed in the session.
Alternatively you can use AJAX and just submit the form when the required steps are completed.
Since you didn't provide any code I won't either, but I figure a nudge in the right direction wouldn't hurt. Come back and post another question when you have some code if you get stuck.

Categories