News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Display individual edit profile fields outside of the array?

Started by samborabora, July 20, 2014, 05:07:47 AM

Previous topic - Next topic

samborabora

I'm trying to rearrange some of the edit profile fields, and most of it has been possible reordering the array:
setupProfileContext(
array(
'avatar_choice', 'hr',
// 'personal_text', 'hr',
'location', 'hr', 'bday1', 'gender', 'hr',
'icq', 'aim', 'msn', 'yim', 'hr',
'usertitle',
//'signature', 'hr',
'karma_good', 'hr',
//'website_title',
'website_url',
)


But I'd like the signature edit field to appear below the custom profile fields which AREN'T displayed via the array. Any way of, say, creating a new array with the signature field in and calling that via the profile edit template?

samborabora

For instance, I'd like to display a bit of html below the avatar bit, but above the location bit. Fine, I imagined I would just make a new array part based upon the 'hr' entry, and call it 'head1' or something, since the 'hr' entry just contains html, but that didn't work either.

Any ideas how to CALL different parts of this array into my profile edit view, and how to add parts the array that are made up of simple html?

margarett

In that case you should probably edit Profile.template.php directly...

Something like:
Find:

', $context['member']['avatar']['image'], '
<ul class="reset">';

Add after:
//my custom HTML here
echo '
<li>Here comes my custom data</li>';
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

samborabora

Quote from: margarett on July 21, 2014, 06:32:35 AM
In that case you should probably edit Profile.template.php directly...

Something like:
Find:

', $context['member']['avatar']['image'], '
<ul class="reset">';

Add after:
//my custom HTML here
echo '
<li>Here comes my custom data</li>';


Is this for the "Edit Profile" part of the profile? Cause I wasn't sure if you could use those kinds of things in the edit profile part, only the "View Profile" section?

margarett

Ah, yes, you're right... That's for the summary, not for the profile edit...

Is that custom HTML a field that is supposed to be stored or just an information bit?
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

samborabora

It's just a <div></div> that says "info" above the fields, nothing complex, but I couldn't understand why I couldn't put it in as a new array? And, I want to place the signature textbox below the custom fields, which are handled by the template, rather than the array.

margarett

I'm not too familiar with that, sorry...
Yet, I do think that only valid fields can go to the "setupProfileContext" array... So a div might not work there...
hr works because of this:

if ($field['type'] == 'hr')
{
echo '
</dl>
<hr width="100%" size="1" class="hrcolor clear" />
<dl>';
}

;)

If you look at the code at Profile.template.php, $field has some properties:
at least: name, value, type, subtext. Maybe you could fill "subtext" with your info? That's what the messengers use ;)

    [msn] => Array
        (
            [type] => text
            [label] => MSN
            [subtext] => Your MSN messenger email address
            [size] => 24
            [permission] => profile_extra
            [input_validate] => lambda_146
            [value] =>
            [input_attr] =>
        )

Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

samborabora

Quote from: margarett on July 21, 2014, 10:53:26 AM
I'm not too familiar with that, sorry...
Yet, I do think that only valid fields can go to the "setupProfileContext" array... So a div might not work there...
hr works because of this:

if ($field['type'] == 'hr')
{
echo '
</dl>
<hr width="100%" size="1" class="hrcolor clear" />
<dl>';
}

;)

If you look at the code at Profile.template.php, $field has some properties:
at least: name, value, type, subtext. Maybe you could fill "subtext" with your info? That's what the messengers use ;)

    [msn] => Array
        (
            [type] => text
            [label] => MSN
            [subtext] => Your MSN messenger email address
            [size] => 24
            [permission] => profile_extra
            [input_validate] => lambda_146
            [value] =>
            [input_attr] =>
        )


Yeah, that first one was what I tried, taking the hr field and creating a new blank field, something like this (I just made this up, but it would be like this):


if ($field['type'] == 'infohead')
{
echo '
</dl>
<div id="infohead"><b>Info</b></div>
<dl>';
}


Then, trying to fit that into the array, like so:

setupProfileContext(
array(
'avatar_choice', 'hr',
// 'personal_text', 'hr',
'infohead',
'location', 'hr', 'bday1', 'gender', 'hr',
'icq', 'aim', 'msn', 'yim', 'hr',
'usertitle',
//'signature', 'hr',
'karma_good', 'hr',
//'website_title',
'website_url',
)


But it didn't work, and I can't figure exactly why. I'd also like to do something like:

setupSignature(
array(
'signature',
)


So I can keep it commented out in the main array, and call it at the end after the custom fields, but this also didn't work. Can I accomplish either of these in any way?

margarett

The first doesn't work because there is no field called "infohead".

Signature has its own treatment, that's why it also doesn't work.
I'd need to study the code in depth to help you a bit more...
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

samborabora

Quote from: margarett on July 21, 2014, 11:17:36 AM
The first doesn't work because there is no field called "infohead".

Signature has its own treatment, that's why it also doesn't work.
I'd need to study the code in depth to help you a bit more...

Is it possible to define your own field, and therefore call it as part of the array? Or would it just be easier to call the different elements manually into the profile? If you can figure out how to call the signature field independently, that would be great, and I could probably just do the same for the other parts.

samborabora

Quote from: margarett on July 21, 2014, 11:17:36 AM
The first doesn't work because there is no field called "infohead".

Signature has its own treatment, that's why it also doesn't work.
I'd need to study the code in depth to help you a bit more...

It's probably easiest if I can just manually display everything the array displays in the profile editor without relying on the array, although this can probably have some sort of effect on the resources/are things like inputs and POST functions still avilable without calling the array?

margarett

Dunno, really :(

I'll try to look at it. Unfortunately I'm extremely busy today :(
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

samborabora

Quote from: margarett on July 22, 2014, 02:13:03 PM
Dunno, really :(

I'll try to look at it. Unfortunately I'm extremely busy today :(

NO problem at all, I really appreciate you and anyone else that might have a chance to find out for me, I'm pretty new to arrays so I can't figure out where they're being called in exactly, or how to define new ones in this particular template. There must be some way of accomplishing this in the most efficient manner possible, surely?

samborabora

So, I just need to get the signature box under the custom fields, and a bit of custom html in between the avatar selector and the rest of the input fields; there's only two ways I cant hink of doing this:


  • Adding the custom html and the custom profile fields individually into the array (so I can order them as I wish)
  • Extracting each component of the array and adding it to the profile template whilst bypassing the rest of the array.

Not sure how to successfully accomplish either, as I said, if hr has been defined as a component of the array, there's no reason why some other html couldn't be defined in addition, I just can't work out how to do add anything to the array. But that would still not help with needing to position the signature box underneath the custom profile fields, which are external from the array.

Anyone know how this could work?

samborabora

Will provide strange, personally satisfying pleasures in exchange for an answer for this one, it's just know to to take out or put in something from the edit profile array?

samborabora

Okay, got the info header in, like so:

setupProfileContext(
      array(
         'infohead',
         'avatar_choice', 'hr',
         // 'personal_text', 'hr',
         'infimghd', 'location', 'hr', 'bday1', 'gender', 'hr',
         'icq', 'aim', 'msn', 'yim', 'hr',
         'usertitle',
         'signature', 'hr',
         'karma_good', 'hr',
         //'website_title',
         'website_url',
      )
   );
}

Then:
'infimghd' => array(
         'type' => 'none',
         'label' => '<span style="color: transparent;position:absolute;"><div id="infoheadimg"></div>',
         'subtext' => '</span>',
      ),

      'location' => array(
         'type' => 'text',
         'label' => $txt['location'],
         'log_change' => true,
         'size' => 50,
         'permission' => 'profile_extra',
         
      ),

Now to get the signature in the right place...

samborabora

Done. I just removed this:

echo '

<dt>
<br />
<div id="sigheadimg"></div>
';

if ($context['show_spellchecking'])
echo '
<input type="button" value="', $txt['spell_check'], '" onclick="spellCheck(\'creator\', \'signature\');" class="button_submit" />';

echo '
</dt>

<textarea class="editor" onkeyup="calcCharLeft();" name="signature" rows="5" cols="50">', $context['member']['signature'], '</textarea><br />';

/*// If there is a limit at all!
if (!empty($context['signature_limits']['max_length']))
echo '
<span class="smalltext">', sprintf($txt['max_sig_characters'], $context['signature_limits']['max_length']), ' <span id="signatureLeft">', $context['signature_limits']['max_length'], '</span></span><br />';*/

if ($context['signature_warning'])
echo '
<span class="smalltext">', $context['signature_warning'], '</span>';

// Load the spell checker?
if ($context['show_spellchecking'])
echo '
<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/spellcheck.js"></script>';

// Some javascript used to count how many characters have been used so far in the signature.
echo '
<script type="text/javascript"><!-- // --><![CDATA[
function tick()
{
if (typeof(document.forms.creator) != "undefined")
{
calcCharLeft();
setTimeout("tick()", 1000);
}
else
setTimeout("tick()", 800);
}

function calcCharLeft()
{
var maxLength = ', $context['signature_limits']['max_length'], ';
var oldSignature = "", currentSignature = document.forms.creator.signature.value;

if (!document.getElementById("signatureLeft"))
return;

if (oldSignature != currentSignature)
{
oldSignature = currentSignature;

if (currentSignature.replace(/\r/, "").length > maxLength)
document.forms.creator.signature.value = currentSignature.replace(/\r/, "").substring(0, maxLength);
currentSignature = document.forms.creator.signature.value.replace(/\r/, "");
}

setInnerHTML(document.getElementById("signatureLeft"), maxLength - currentSignature.length);
}

addLoadEvent(tick);
// ]]></script>
';


From this:
// Show the signature editing box?
function template_profile_signature_modify()
{
global $txt, $context, $settings;

}


And dumped it into the profile.template.php where I wanted it to appear. Can't see why any of this wouldn't work, tbh :D

samborabora

Except now it shoves signature inbetween the Secret Question Answer and Current Password box of Edit Settings also :/

samborabora

Never mind, I wrapped it up inside
if (!empty($context['custom_fields']))
{


So, now it looks like a total mess, but does what it says on the tin :P

Advertisement: