MyBB Community Forums

Full Version: Get Custom Profile Field Value
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I created a custom profile field. On my post bit, I have a button that when is clicked, I would like an on screen pop up window to open up and display the value of the custom profile field that I created. I was able to do this on MyBB 1.6 by doing this, but for some reason, 1.8 doesn't allow me:

<button onclick="myFunction()">Get Value</button>

<script>
function myFunction() {
    alert({$post['fid4']});
}
</script>

Any suggestions on how to accomplish this or something similar? 

Thank you.


*EDIT*

I've decided to clean up how I was retrieving the custom profile field with a better popup. Here is what I have:

HTML Code
<div class="box">
	<a class="button" href="#popup1">Info</a>
</div>

<div id="popup1" class="overlay">
	<div class="popup">
		<h2>Info</h2>
		<a class="close" href="#">×</a>
		<div class="content">
			<span style="color:#000000">{$post['fid4']}</span>
		</div>
	</div>
</div>

CSS Code
h1 {
  text-align: center;
  font-family: Tahoma, Arial, sans-serif;
  color: orange;
  margin: 100px 0;
}

.button {
  font-size: 1em;
  padding: 10px;
  color: #fff;
  border: 2px solid orange;
  border-radius: 20px/50px;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.3s ease-out;
}
.button:hover {
  background: orange;
}

.overlay {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.7);
  transition: opacity 500ms;
  visibility: hidden;
  opacity: 0;
}
.overlay:target {
  visibility: visible;
  opacity: 1;
}

.popup {
  margin: 70px auto;
  padding: 20px;
  background: #fff;
  border-radius: 5px;
  width: 30%;
  position: relative;
  transition: all 5s ease-in-out;
}

.popup h2 {
  margin-top: 0;
  color: #333;
  font-family: Tahoma, Arial, sans-serif;
}
.popup .close {
  position: absolute;
  top: 20px;
  right: 30px;
  transition: all 200ms;
  font-size: 30px;
  font-weight: bold;
  text-decoration: none;
  color: #333;
}
.popup .close:hover {
  color: orange;
}
.popup .content {
  max-height: 30%;
  overflow: auto;
}

My question is what it was before. How would I get each individual's custom profile field? Right now, it's only picking up MY custom profile field, if that makes sense. So for each post from a user, that user will have an 'Info' button linked to them on their post in the postbit. I want that button linked to their custom profile field and whatever they entered in it, so if I click on an individual's button, I'll see what they put in their custom profile field, so on and so forth.
You could use Template Conditionals in postbit_profilefield like such (as an example/demo):
<if $post['fieldname'] == 'Test' then>
	<script type=text/javascript>alert('{$post['fieldvalue']}');</script>
</if>
(02-03-2016, 12:25 AM)nth Wrote: [ -> ]You could use Template Conditionals in postbit_profilefield like such (as an example/demo):
<if $post['fieldname'] == 'Test' then>
	<script type=text/javascript>alert('{$post['fieldvalue']}');</script>
</if>

Let me rephrase this. I got the popup to work. How would I go about getting the custom profile field value of another individual on the forum? If that makes sense.
If it has to be on postbit, then you'll need to either have a plugin (.m. knows about a lot of plugins) or you'll need to create a new variable in the showthread.php file.
(02-03-2016, 12:44 AM)nth Wrote: [ -> ]If it has to be on postbit, then you'll need to either have a plugin (.m. knows about a lot of plugins) or you'll need to create a new variable in the showthread.php file.

Thank you very much. If I choose the new variable in the showthread, how would I go about that?
It really depends. How is it going to work? Let's say I was a user on your forum..

Who's profile field value would I have?
Who's profile value would you have?
(02-03-2016, 12:48 AM)nth Wrote: [ -> ]It really depends. How is it going to work? Let's say I was a user on your forum..

Who's profile field value would I have?
Who's profile value would you have?

So I'm having every user input their own value into the profile field, but I want other users to be able to click the button on the post bit of another individual and receive their value. 

Here's an example:

User1's custom field = cat
User2's custom field = dog

If user1 clicks on the button in the post bit on user2's post, it'll pop up with 'dog'. But if user1 clicks his own button, it pops up as 'cat'. I essentially want to get the value of the custom field for any individual the user clicks the button on in the post bit.
Can you give me the code of your button postbit please.
As of right now, this is what I have for the popup:

	<script>
function myFunction() {
    alert("{$post['fid4']}");
}
		
</script>

<button title="Get User's Info" onclick="myFunction()">Get Info</button>

Right now, it only comes up with the individual's custom profile field and no one elses.
And what template is this in?

In postbit, under:
	<div class="post_meta" id="post_meta_{$post['pid']}">
		{$post['iplogged']}
	</div>

I added:
	    <script>
function myFunction(field) {
    alert(field);
}
        
</script>

<button title="Get User's Info" onclick="myFunction('{$post['fieldvalue']}')">Get Info</button>

Please note: This will only work for the last profile field.
Pages: 1 2